GROOVY-12155: decode process output streams using the native encoding#2700
Open
paulk-asert wants to merge 1 commit into
Open
GROOVY-12155: decode process output streams using the native encoding#2700paulk-asert wants to merge 1 commit into
paulk-asert wants to merge 1 commit into
Conversation
with thanks to https://github.com/netliomax25-code for identifying the problem
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2700 +/- ##
==================================================
+ Coverage 69.1083% 69.1143% +0.0059%
- Complexity 34235 34248 +13
==================================================
Files 1537 1537
Lines 129310 129377 +67
Branches 23478 23503 +25
==================================================
+ Hits 89364 89418 +54
+ Misses 31936 31935 -1
- Partials 8010 8024 +14
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 8a75dea Learn more about TestLens at testlens.app. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR (GROOVY-12155) updates Groovy’s Process GDK methods to decode/encode process streams using the OS native encoding by default (instead of Charset.defaultCharset()), with an opt-in system property override and new charset-aware overloads.
Changes:
- Default
Process.text,waitForProcessOutput,consumeProcessOutput, andwaitForResultdecoding now uses the OS native encoding (orgroovy.process.encodingwhen set). - Added charset-accepting overloads for process stream consumption and result capture APIs.
- Extended
ProcessTestto validate charset override behavior, and modernized the mock process streams.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/test/groovy/groovy/ProcessTest.groovy | Adds regression tests for native/process encoding behavior and updates MockProcess stream setup. |
| src/main/java/org/codehaus/groovy/runtime/ProcessGroovyMethods.java | Implements native-encoding defaulting, groovy.process.encoding override, and new charset overloads for process stream APIs. |
| src/main/java/org/codehaus/groovy/runtime/FlushingStreamWriter.java | Adds a charset-aware constructor to support explicit encoding for process stdin writes. |
Comment on lines
+140
to
143
| public static String getText(Process self, Charset charset) throws IOException { | ||
| String text = IOGroovyMethods.getText(new BufferedReader(new InputStreamReader(self.getInputStream(), charset))); | ||
| closeStreams(self); | ||
| return text; |
Comment on lines
+94
to
+97
| void testProcessTextDefaultsToTheNativeEncoding() { | ||
| def bytes = [0xE9] as byte[] | ||
| def expected = new String(bytes, Charset.forName(System.getProperty("native.encoding"))) | ||
| assert expected == new MockProcess(bytes).text |
Comment on lines
+110
to
+114
| void testProcessEncodingPropertyIgnoredWhenNotAValidCharset() { | ||
| System.setProperty(PROCESS_ENCODING, "no-such-charset") | ||
| def bytes = [0xE9] as byte[] | ||
| def expected = new String(bytes, Charset.forName(System.getProperty("native.encoding"))) | ||
| assert expected == new MockProcess(bytes).text |
Comment on lines
160
to
163
| @AfterEach | ||
| void tearDown() { | ||
| System.clearProperty(PROCESS_ENCODING) | ||
| myProcess.destroy() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
see https://issues.apache.org/jira/browse/GROOVY-12155
with thanks to https://github.com/netliomax25-code for identifying the problem