neilcsmith-net commented on code in PR #4396:
URL: https://github.com/apache/netbeans/pull/4396#discussion_r923549604
##########
java/maven/src/org/netbeans/modules/maven/execute/CommandLineOutputHandler.java:
##########
@@ -827,30 +827,45 @@ public ExecutionEventObject.Tree getExecutionTree() {
}
}
-
- private static Charset getNativeCharset() {
+
+ /**
+ * Returns the preferred Charset that is obtained by checking the
following system properties:
+ * stdout.encoding, sun.stdout.encoding, native.encoding,
Charset.defaultCharset()
+ * @see
org.netbeans.api.extexecution.base.BaseExecutionService#getInputOutputEncoding
+ * @return Charset
+ */
+ private static Charset getPreferredCharset() {
// The CommandLineOutputHandler used the default charset to convert
// output from command line invocations to strings. That encoding is
// derived from the system file.encoding. From JDK 18 onwards its
// default value changed to UTF-8.
- // JDK 18+ exposes the native encoding as the new system property
+ // JDK 17+ exposes the native encoding as the new system property
// native.encoding, prior versions don't have that property and will
// report NULL for it.
- // The algorithm is simple: If native.encoding is set, it will be used
- // else the old default will be queried via Charset#defaultCharset.
- String nativeEncoding = System.getProperty("native.encoding");
- Charset nativeCharset = null;
- if (nativeEncoding != null) {
+ // To account for the behavior of JEP400 the following order is used
to determine the encoding:
+ // stdout.encoding, sun.stdout.encoding, native.encoding,
Charset.defaultCharset()
+ String[] encodingSystemProperties = new String[]{"stdout.encoding,
sun.stdout.encoding, native.encoding"};
Review Comment:
This is one String not three!
##########
ide/extexecution.base/src/org/netbeans/api/extexecution/base/BaseExecutionService.java:
##########
@@ -140,6 +140,45 @@ public static BaseExecutionService newService(@NonNull
Callable<? extends Proces
return new BaseExecutionService(processCreator, descriptor);
}
+ /**
+ * Infers the output encoding from the relevant system properties, if
those should all be <code>null</code>
+ * then this will fallback to <code>Charset.defaultCharset()</code>
+ *
+ * Since JDK 18 and JEP400 Console.charset() is used for the console's
encoding instead of <code>Charset.defaultCharset()</code>.
+ * Console.charset() is exposed via stdout.encoding/sun.stdout.encoding.
+ * If ran with JDK<=16 stdout.encoding and native.encoding should be null
and the old default of <code>Charset.defaultCharset()</code> will be used to
match pre JEP400 behavior.
+ *
+ * The checking order for the encoding is stdout.encoding,
sun.stdout.encoding, native.encoding, <code>Charset.defaultCharset()</code>
+ *
+ * @see
org.netbeans.modules.maven.execute.CommandLineOutputHandler#getPreferredCharset
+ *
+ * @return inferred encoding as Charset
+ */
+ private static Charset getInputOutputEncoding(){
+ String[] encodingSystemProperties = new String[]{"stdout.encoding,
sun.stdout.encoding, native.encoding"};
Review Comment:
This is one String not three!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists