neilcsmith-net commented on code in PR #4396:
URL: https://github.com/apache/netbeans/pull/4396#discussion_r923357594


##########
ide/extexecution.base/src/org/netbeans/api/extexecution/base/BaseExecutionService.java:
##########
@@ -140,6 +140,43 @@ 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 these properties 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>
+     * 
+     * @return inferred encoding as Charset
+     */
+    private static Charset getInputOutputEncoding(){
+        String[] encodingSystemProperties = new String[]{"stdout.encoding, 
sun.stdout.encoding, native.encoding"};
+
+        Charset preferredCharset = null;
+        for(String encodingProperty : encodingSystemProperties){
+            String encodingPropertyValue = 
System.getProperty(encodingProperty);
+            if(encodingPropertyValue == null){
+                continue;
+            }
+
+            try {
+                preferredCharset = Charset.forName(encodingPropertyValue);

Review Comment:
   Isn't this missing a `break`?!
   
   Could also chain the variant of System::getProperty with default values to 
get rid of the loop - pros and cons to validating each value.



##########
ide/extexecution.base/src/org/netbeans/api/extexecution/base/BaseExecutionService.java:
##########
@@ -140,6 +140,43 @@ 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 these properties should be null and the old default 
of <code>Charset.defaultCharset()</code> will be used to match pre JEP400 
behavior.

Review Comment:
   At least `sun.stdout.encoding` may not be `null` on JDK<=16. That predates 
JEP400.



##########
ide/extexecution.base/src/org/netbeans/api/extexecution/base/BaseExecutionService.java:
##########
@@ -140,6 +140,43 @@ 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 these properties 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>
+     * 
+     * @return inferred encoding as Charset
+     */
+    private static Charset getInputOutputEncoding(){
+        String[] encodingSystemProperties = new String[]{"stdout.encoding, 
sun.stdout.encoding, native.encoding"};
+
+        Charset preferredCharset = null;
+        for(String encodingProperty : encodingSystemProperties){
+            String encodingPropertyValue = 
System.getProperty(encodingProperty);
+            if(encodingPropertyValue == null){
+                continue;
+            }
+
+            try {
+                preferredCharset = Charset.forName(encodingPropertyValue);
+            } catch (Exception ex) {
+                LOGGER.log(java.util.logging.Level.WARNING, "Failed to get 
charset for '" + encodingProperty + "' value : '" + encodingPropertyValue + 
"'", ex);
+            }
+
+            if(preferredCharset != null){

Review Comment:
   Please correct the spacing.



-- 
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

Reply via email to