Skip to content

Commit d1ba02f

Browse files
authored
Merge pull request #21291 from pshipton/defutf851
(0.51) For jdk24+ set the default encoding to UTF-8
2 parents ca40900 + 031538c commit d1ba02f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

jcl/src/java.base/share/classes/java/lang/System.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ public final class System {
163163
/*[IF JAVA_SPEC_VERSION >= 11]*/
164164
private static boolean hasSetErrEncoding;
165165
private static boolean hasSetOutEncoding;
166+
/*[IF JAVA_SPEC_VERSION < 24]*/
166167
private static String consoleDefaultEncoding;
168+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
167169
/* The consoleDefaultCharset is different from the default console encoding when the encoding
168170
* doesn't exist, or isn't available at startup. Some character sets are not available in the
169171
* java.base module, there are more in the jdk.charsets module, and so are not used at startup.
@@ -228,7 +230,9 @@ public final class System {
228230
* if different from the default console Charset.
229231
*
230232
* consoleDefaultCharset must be initialized before calling.
233+
/*[IF JAVA_SPEC_VERSION < 24]
231234
* consoleDefaultEncoding must be initialized before calling with fallback set to true.
235+
/*[ENDIF] JAVA_SPEC_VERSION < 24
232236
*/
233237
static Charset getCharset(boolean isStdout, boolean fallback) {
234238
/*[IF JAVA_SPEC_VERSION >= 19]*/
@@ -248,6 +252,7 @@ static Charset getCharset(boolean isStdout, boolean fallback) {
248252
// ignore unsupported or invalid encodings
249253
}
250254
}
255+
/*[IF JAVA_SPEC_VERSION < 24]*/
251256
if (fallback && (consoleDefaultEncoding != null)) {
252257
try {
253258
Charset newCharset = Charset.forName(consoleDefaultEncoding);
@@ -260,6 +265,7 @@ static Charset getCharset(boolean isStdout, boolean fallback) {
260265
// ignore unsupported or invalid encodings
261266
}
262267
}
268+
/*[ENDIF] JAVA_SPEC_VERSION < 24 */
263269
return null;
264270
}
265271

@@ -419,8 +425,12 @@ static void afterClinitInitialization() {
419425
Properties props = internalGetProperties();
420426
/*[IF JAVA_SPEC_VERSION >= 11]*/
421427
/*[IF JAVA_SPEC_VERSION >= 18]*/
428+
/*[IF JAVA_SPEC_VERSION >= 24]*/
429+
consoleDefaultCharset = sun.nio.cs.UTF_8.INSTANCE;
430+
/*[ELSE] JAVA_SPEC_VERSION >= 24 */
422431
consoleDefaultEncoding = props.getProperty("native.encoding"); //$NON-NLS-1$
423432
consoleDefaultCharset = Charset.forName(consoleDefaultEncoding, sun.nio.cs.UTF_8.INSTANCE);
433+
/*[ENDIF] JAVA_SPEC_VERSION >= 24 */
424434
/*[ELSE] JAVA_SPEC_VERSION >= 18 */
425435
String fileEncodingProp = props.getProperty("file.encoding"); //$NON-NLS-1$
426436
// Do not call Charset.defaultEncoding() since this would initialize the default encoding

0 commit comments

Comments
 (0)