Skip to content

8359732: Make standard i/o encoding related system properties StaticProperty #25860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/java.base/share/classes/java/io/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import jdk.internal.access.SharedSecrets;
import jdk.internal.io.JdkConsoleImpl;
import jdk.internal.io.JdkConsoleProvider;
import jdk.internal.util.StaticProperty;
import sun.nio.cs.UTF_8;

/**
Expand Down Expand Up @@ -555,9 +556,9 @@ private static UnsupportedOperationException newUnsupportedOperationException()

private static final boolean istty = istty();
private static final Charset STDIN_CHARSET =
Charset.forName(System.getProperty("stdin.encoding"), UTF_8.INSTANCE);
Charset.forName(StaticProperty.stdinEncoding(), UTF_8.INSTANCE);
private static final Charset STDOUT_CHARSET =
Charset.forName(System.getProperty("stdout.encoding"), UTF_8.INSTANCE);
Charset.forName(StaticProperty.stdoutEncoding(), UTF_8.INSTANCE);
private static final Console cons = instantiateConsole();
static {
// Set up JavaIOAccess in SharedSecrets
Expand Down
4 changes: 3 additions & 1 deletion src/java.base/share/classes/java/lang/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import jdk.internal.util.StaticProperty;

/**
* A collection of static methods that provide convenient access to {@link System#in}
* and {@link System#out} for line-oriented input and output.
Expand Down Expand Up @@ -187,7 +189,7 @@ public static String readln(String prompt) {
*/
static synchronized BufferedReader reader() {
if (br == null) {
String enc = System.getProperty("stdin.encoding", "");
String enc = StaticProperty.stdinEncoding();
Charset cs = Charset.forName(enc, StandardCharsets.UTF_8);
br = new BufferedReader(new InputStreamReader(System.in, cs));
}
Expand Down
41 changes: 34 additions & 7 deletions src/java.base/share/classes/jdk/internal/util/StaticProperty.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,7 +28,7 @@
import java.util.Properties;

/**
* System Property access for internal use only.
* System Property access for `java.base` module internal use only.
* Read-only access to System property values initialized during Phase 1
* are cached. Setting, clearing, or modifying the value using
* {@link System#setProperty} or {@link System#getProperties()} is ignored.
Expand All @@ -48,8 +48,11 @@ public final class StaticProperty {
private static final String JAVA_IO_TMPDIR;
private static final String NATIVE_ENCODING;
private static final String FILE_ENCODING;
private static final String JAVA_PROPERTIES_DATE;
private static final String STDIN_ENCODING;
private static final String STDERR_ENCODING;
private static final String STDOUT_ENCODING;
private static final String SUN_JNU_ENCODING;
private static final String JAVA_PROPERTIES_DATE;
private static final String JAVA_LOCALE_USE_OLD_ISO_CODES;
private static final String OS_NAME;
private static final String OS_ARCH;
Expand Down Expand Up @@ -86,8 +89,11 @@ private StaticProperty() {}
JDK_SERIAL_FILTER_FACTORY = getProperty(props, "jdk.serialFilterFactory", null);
NATIVE_ENCODING = getProperty(props, "native.encoding");
FILE_ENCODING = getProperty(props, "file.encoding");
JAVA_PROPERTIES_DATE = getProperty(props, "java.properties.date", null);
STDIN_ENCODING = getProperty(props, "stdin.encoding");
STDERR_ENCODING = getProperty(props, "stderr.encoding");
STDOUT_ENCODING = getProperty(props, "stdout.encoding");
SUN_JNU_ENCODING = getProperty(props, "sun.jnu.encoding");
JAVA_PROPERTIES_DATE = getProperty(props, "java.properties.date", null);
JAVA_LOCALE_USE_OLD_ISO_CODES = getProperty(props, "java.locale.useOldISOCodes", "");
OS_NAME = getProperty(props, "os.name");
OS_ARCH = getProperty(props, "os.arch");
Expand Down Expand Up @@ -218,10 +224,24 @@ public static String fileEncoding() {
}

/**
* {@return the {@code java.properties.date} system property}
* {@return the {@code stdin.encoding} system property}
*/
public static String javaPropertiesDate() {
return JAVA_PROPERTIES_DATE;
public static String stdinEncoding() {
return STDIN_ENCODING;
}

/**
* {@return the {@code stderr.encoding} system property}
*/
public static String stderrEncoding() {
return STDERR_ENCODING;
}

/**
* {@return the {@code stdout.encoding} system property}
*/
public static String stdoutEncoding() {
return STDOUT_ENCODING;
}

/**
Expand All @@ -231,6 +251,13 @@ public static String jnuEncoding() {
return SUN_JNU_ENCODING;
}

/**
* {@return the {@code java.properties.date} system property}
*/
public static String javaPropertiesDate() {
return JAVA_PROPERTIES_DATE;
}

/**
* {@return the {@code java.locale.useOldISOCodes} system property}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import javax.security.auth.x500.X500Principal;
import java.util.Base64;

import jdk.internal.util.StaticProperty;

import sun.security.pkcs12.PKCS12KeyStore;
import sun.security.provider.certpath.CertPathConstraintsParameters;
import sun.security.util.*;
Expand Down Expand Up @@ -3549,7 +3551,7 @@ private String inputStringFromStdin(String prompt) throws Exception {

private static BufferedReader stdinAwareReader(InputStream in) {
InputStreamReader reader = in == System.in
? new InputStreamReader(in, Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset()))
? new InputStreamReader(in, Charset.forName(StaticProperty.stdinEncoding(), Charset.defaultCharset()))
: new InputStreamReader(in);
return new BufferedReader(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package sun.security.util;

import jdk.internal.util.StaticProperty;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.ConfirmationCallback;
Expand Down Expand Up @@ -131,7 +133,7 @@ public void handle(Callback[] callbacks)

/* Reads a line of input */
private String readLine() throws IOException {
Charset charset = Charset.forName(System.getProperty("stdin.encoding"), Charset.defaultCharset());
Charset charset = Charset.forName(StaticProperty.stdinEncoding(), Charset.defaultCharset());
InputStreamReader reader = new InputStreamReader(System.in, charset);
String result = new BufferedReader(reader).readLine();
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -29,7 +29,6 @@
import java.security.Provider;

import jdk.internal.util.OperatingSystem;
import jdk.internal.util.StaticProperty;
import org.ietf.jgss.Oid;
import static sun.security.util.SecurityConstants.PROVIDER_VER;

Expand Down Expand Up @@ -95,7 +94,7 @@ private static Oid[] getMechOIDs() {
};
case WINDOWS -> new String[]{
// Full path needed, DLL is in jre/bin
StaticProperty.javaHome() + "\\bin\\sspi_bridge.dll",
System.getProperty("java.home") + "\\bin\\sspi_bridge.dll",
};
case AIX -> new String[]{
"/opt/freeware/lib64/libgssapi_krb5.so",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
package jdk.incubator.vector;

import jdk.internal.util.StaticProperty;
import jdk.internal.vm.annotation.DontInline;
import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.Stable;
Expand Down Expand Up @@ -70,7 +69,7 @@ static Library getInstance() {
}

static String getDefaultName() {
return switch (StaticProperty.osArch()) {
return switch (System.getProperty("os.arch")) {
case "amd64", "x86_64" -> SVML;
case "aarch64", "riscv64" -> SLEEF;
default -> JAVA;
Expand Down