65
65
66
66
/*[IF JAVA_SPEC_VERSION >= 20]*/
67
67
import java .lang .reflect .Field ;
68
- import jdk .internal .util .SystemProps ;
69
68
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
69
+ /*[IF JAVA_SPEC_VERSION >= 17]*/
70
+ import jdk .internal .util .SystemProps ;
71
+ /*[ENDIF] JAVA_SPEC_VERSION >= 17 */
70
72
71
73
/*[IF JAVA_SPEC_VERSION >= 24]*/
72
74
import java .net .URL ;
@@ -152,11 +154,8 @@ public final class System {
152
154
private static final int sysPropID_OSEncoding = 3 ;
153
155
private static String osEncoding ;
154
156
155
- private static final int sysPropID_DefaultTmpDir = 4 ;
156
- private static String defaultTmpDir ;
157
-
158
157
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
159
- private static final int sysPropID_zOSAutoConvert = 5 ;
158
+ private static final int sysPropID_zOSAutoConvert = 4 ;
160
159
private static String zOSAutoConvert ;
161
160
/*[ENDIF] (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64) */
162
161
@@ -172,10 +171,6 @@ public final class System {
172
171
*/
173
172
private static Charset consoleDefaultCharset ;
174
173
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
175
- /*[IF JAVA_SPEC_VERSION >= 19]*/
176
- private static String stdoutProp ;
177
- private static String stderrProp ;
178
- /*[ENDIF] JAVA_SPEC_VERSION >= 19 */
179
174
180
175
/*[IF JAVA_SPEC_VERSION >= 9]*/
181
176
static java .lang .ModuleLayer bootLayer ;
@@ -213,7 +208,6 @@ public final class System {
213
208
if (osEncoding == null ) {
214
209
osEncoding = definedOSEncoding ;
215
210
}
216
- defaultTmpDir = getSysPropBeforePropertiesInitialized (sysPropID_DefaultTmpDir );
217
211
218
212
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
219
213
/* As part of better handling of JEP400 constraints on z/OS, the com.ibm.autocvt property
@@ -236,7 +230,7 @@ public final class System {
236
230
*/
237
231
static Charset getCharset (boolean isStdout , boolean fallback ) {
238
232
/*[IF JAVA_SPEC_VERSION >= 19]*/
239
- String primary = isStdout ? stdoutProp : stderrProp ;
233
+ String primary = internalGetProperties (). getProperty ( isStdout ? "stdout.encoding" : "stderr.encoding" ); //$NON-NLS-1$ //$NON-NLS-2$
240
234
/*[ELSE] JAVA_SPEC_VERSION >= 19 */
241
235
String primary = internalGetProperties ().getProperty (isStdout ? "sun.stdout.encoding" : "sun.stderr.encoding" ); //$NON-NLS-1$ //$NON-NLS-2$
242
236
/*[ENDIF] JAVA_SPEC_VERSION >= 19 */
@@ -279,20 +273,6 @@ static PrintStream createConsole(FileDescriptor desc, Charset charset) {
279
273
BufferedOutputStream bufStream = new BufferedOutputStream (new FileOutputStream (desc ));
280
274
Charset consoleCharset = charset == null ? consoleDefaultCharset : charset ;
281
275
282
- /*[IF JAVA_SPEC_VERSION >= 19]*/
283
- Properties props = internalGetProperties ();
284
- // If the user didn't set the encoding property, set it now.
285
- if (FileDescriptor .out == desc ) {
286
- if (null == stdoutProp ) {
287
- props .put ("stdout.encoding" , consoleCharset .name ()); //$NON-NLS-1$
288
- }
289
- } else if (FileDescriptor .err == desc ) {
290
- if (null == stderrProp ) {
291
- props .put ("stderr.encoding" , consoleCharset .name ()); //$NON-NLS-1$
292
- }
293
- }
294
- /*[ENDIF] JAVA_SPEC_VERSION >= 19 */
295
-
296
276
/*[IF PLATFORM-mz31 | PLATFORM-mz64]*/
297
277
return ConsolePrintStream .localize (bufStream , true , consoleCharset );
298
278
/*[ELSE]*/
@@ -323,12 +303,6 @@ static void finalizeConsoleEncoding() {
323
303
setOut (createConsole (FileDescriptor .out , stdoutCharset ));
324
304
}
325
305
}
326
-
327
- /*[IF JAVA_SPEC_VERSION >= 19]*/
328
- // Cache the final system property values so they can be restored if ensureProperties(false) is called.
329
- stdoutProp = systemProperties .getProperty ("stdout.encoding" ); //$NON-NLS-1$
330
- stderrProp = systemProperties .getProperty ("stderr.encoding" ); //$NON-NLS-1$
331
- /*[ENDIF] JAVA_SPEC_VERSION >= 19 */
332
306
}
333
307
/*[ELSE]*/
334
308
/*[IF Sidecar18-SE-OpenJ9]*/
@@ -389,9 +363,9 @@ static void afterClinitInitialization() {
389
363
// Fill in the properties from the VM information.
390
364
ensureProperties (true );
391
365
392
- /*[IF JAVA_SPEC_VERSION > = 11]*/
366
+ /*[IF JAVA_SPEC_VERSION = = 11]*/
393
367
initJCLPlatformEncoding ();
394
- /*[ENDIF] JAVA_SPEC_VERSION > = 11 */
368
+ /*[ENDIF] JAVA_SPEC_VERSION = = 11 */
395
369
396
370
/*[REM] Initialize the JITHelpers needed in J9VMInternals since the class can't do it itself */
397
371
try {
@@ -729,7 +703,7 @@ private static void ensureProperties(boolean isInitialization) {
729
703
/*[ENDIF] OpenJ9-RawBuild */
730
704
731
705
/*[IF JAVA_SPEC_VERSION > 11]*/
732
- Map <String , String > initializedProperties = new Hashtable < String , String >();
706
+ Map <String , String > initializedProperties = new HashMap < >();
733
707
/*[ELSE] JAVA_SPEC_VERSION > 11
734
708
Properties initializedProperties = new Properties();
735
709
/*[ENDIF] JAVA_SPEC_VERSION > 11 */
@@ -741,9 +715,11 @@ private static void ensureProperties(boolean isInitialization) {
741
715
if (osEncoding != null ) {
742
716
initializedProperties .put ("os.encoding" , osEncoding ); //$NON-NLS-1$
743
717
}
744
- /*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/
745
718
initializedProperties .put ("ibm.system.encoding" , platformEncoding ); //$NON-NLS-1$
719
+ /*[IF JAVA_SPEC_VERSION < 17]*/
720
+ /*[PR The launcher apparently needs sun.jnu.encoding property or it does not work]*/
746
721
initializedProperties .put ("sun.jnu.encoding" , platformEncoding ); //$NON-NLS-1$
722
+ /*[ENDIF] JAVA_SPEC_VERSION < 17 */
747
723
/*[IF JAVA_SPEC_VERSION == 8]*/
748
724
initializedProperties .put ("file.encoding.pkg" , "sun.io" ); //$NON-NLS-1$ //$NON-NLS-2$
749
725
/*[ENDIF] JJAVA_SPEC_VERSION == 8 */
@@ -769,6 +745,9 @@ private static void ensureProperties(boolean isInitialization) {
769
745
initializedProperties .put ("jfr.unsupported.vm" , "true" ); //$NON-NLS-1$ //$NON-NLS-2$
770
746
/*[ENDIF] JFR_SUPPORT */
771
747
748
+ /*[IF JAVA_SPEC_VERSION >= 17]*/
749
+ initializedProperties .putAll (SystemProps .initProperties ());
750
+ /*[ELSE] JAVA_SPEC_VERSION >= 17 */
772
751
String [] list = getPropertyList ();
773
752
for (int i = 0 ; i < list .length ; i += 2 ) {
774
753
String key = list [i ];
@@ -779,43 +758,12 @@ private static void ensureProperties(boolean isInitialization) {
779
758
initializedProperties .put (key , list [i +1 ]);
780
759
}
781
760
initializedProperties .put ("file.encoding" , fileEncoding ); //$NON-NLS-1$
782
-
783
- /*[IF JAVA_SPEC_VERSION >= 17]*/
784
- /* Set native.encoding after setting all the defined properties, it can't be modified by using -D on the command line */
785
- initializedProperties .put ("native.encoding" , platformEncoding ); //$NON-NLS-1$
786
761
/*[ENDIF] JAVA_SPEC_VERSION >= 17 */
787
762
788
763
/*[IF (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64)]*/
789
764
initializedProperties .put ("com.ibm.autocvt" , zOSAutoConvert ); //$NON-NLS-1$
790
765
/*[ENDIF] (JAVA_SPEC_VERSION >= 21) & (PLATFORM-mz31 | PLATFORM-mz64) */
791
766
792
- /*[IF JAVA_SPEC_VERSION >= 19]*/
793
- if (null != stdoutProp ) {
794
- // Reinitialize required properties if ensureProperties(false) is called.
795
- initializedProperties .put ("stdout.encoding" , stdoutProp ); //$NON-NLS-1$
796
- } else {
797
- stdoutProp = initializedProperties .get ("stdout.encoding" ); //$NON-NLS-1$
798
- if (null == stdoutProp ) {
799
- stdoutProp = initializedProperties .get ("sun.stdout.encoding" ); //$NON-NLS-1$
800
- if (null != stdoutProp ) {
801
- initializedProperties .put ("stdout.encoding" , stdoutProp ); //$NON-NLS-1$
802
- }
803
- }
804
- }
805
- if (null != stderrProp ) {
806
- // Reinitialize required properties if ensureProperties(false) is called.
807
- initializedProperties .put ("stderr.encoding" , stderrProp ); //$NON-NLS-1$
808
- } else {
809
- stderrProp = initializedProperties .get ("stderr.encoding" );
810
- if (null == stderrProp ) { //$NON-NLS-1$
811
- stderrProp = initializedProperties .get ("sun.stderr.encoding" ); //$NON-NLS-1$
812
- if (null != stderrProp ) {
813
- initializedProperties .put ("stderr.encoding" , stderrProp ); //$NON-NLS-1$
814
- }
815
- }
816
- }
817
- /*[ENDIF] JAVA_SPEC_VERSION >= 19 */
818
-
819
767
/* java.lang.VersionProps.init() eventually calls into System.setProperty() where propertiesInitialized needs to be true */
820
768
propertiesInitialized = true ;
821
769
@@ -1087,6 +1035,7 @@ public static String setProperty(String prop, String value) {
1087
1035
return (String )systemProperties .setProperty (prop , value );
1088
1036
}
1089
1037
1038
+ /*[IF JAVA_SPEC_VERSION < 17]*/
1090
1039
/**
1091
1040
* Answers an array of Strings containing key..value pairs
1092
1041
* (in consecutive array elements) which represent the
@@ -1096,13 +1045,14 @@ public static String setProperty(String prop, String value) {
1096
1045
* @return the default values for the system properties.
1097
1046
*/
1098
1047
private static native String [] getPropertyList ();
1048
+ /*[ENDIF] JAVA_SPEC_VERSION < 17 */
1099
1049
1100
- /*[IF JAVA_SPEC_VERSION > = 11]*/
1050
+ /*[IF JAVA_SPEC_VERSION = = 11]*/
1101
1051
/**
1102
1052
* Invoke JCL native to initialize platform encoding explicitly.
1103
1053
*/
1104
1054
private static native void initJCLPlatformEncoding ();
1105
- /*[ENDIF] JAVA_SPEC_VERSION > = 11 */
1055
+ /*[ENDIF] JAVA_SPEC_VERSION = = 11 */
1106
1056
1107
1057
/**
1108
1058
* Before propertiesInitialized is set to true,
@@ -1319,18 +1269,8 @@ public static void setProperties(Properties p) {
1319
1269
1320
1270
static void checkTmpDir () {
1321
1271
/*[IF JAVA_SPEC_VERSION >= 20]*/
1322
- String tmpDir = internalGetProperties ().getProperty ("java.io.tmpdir" ); //$NON-NLS-1$
1323
- if (!defaultTmpDir .equals (tmpDir )) {
1324
- try {
1325
- Field systemProps = SystemProps .class .getDeclaredField ("customTmpdir" ); //$NON-NLS-1$
1326
- systemProps .setAccessible (true );
1327
- systemProps .set (null , tmpDir );
1328
- if (SystemProps .isBadIoTmpdir ()) {
1329
- System .err .println ("WARNING: java.io.tmpdir directory does not exist" ); //$NON-NLS-1$
1330
- }
1331
- } catch (IllegalAccessException | NoSuchFieldException e ) {
1332
- throw new InternalError (e );
1333
- }
1272
+ if (SystemProps .isBadIoTmpdir ()) {
1273
+ System .err .println ("WARNING: java.io.tmpdir directory does not exist" ); //$NON-NLS-1$
1334
1274
}
1335
1275
/*[ENDIF] JAVA_SPEC_VERSION >= 20 */
1336
1276
}
0 commit comments