8300916: Re-examine the initialization of JNU Charset in StaticProperty

Reviewed-by: mchung, alanb
This commit is contained in:
Naoto Sato 2023-01-30 17:06:44 +00:00
parent f4592b1471
commit 323813985b
4 changed files with 23 additions and 34 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
@ -54,10 +54,9 @@
package java.lang;
import java.io.*;
import java.nio.charset.Charset;
import java.util.*;
import jdk.internal.util.StaticProperty;
import static java.lang.ProcessImpl.JNU_CHARSET;
final class ProcessEnvironment
@ -165,7 +164,7 @@ final class ProcessEnvironment
}
public static Variable valueOfQueryOnly(String str) {
return new Variable(str, str.getBytes(StaticProperty.jnuCharset()));
return new Variable(str, str.getBytes(JNU_CHARSET));
}
public static Variable valueOf(String str) {
@ -174,7 +173,7 @@ final class ProcessEnvironment
}
public static Variable valueOf(byte[] bytes) {
return new Variable(new String(bytes, StaticProperty.jnuCharset()), bytes);
return new Variable(new String(bytes, JNU_CHARSET), bytes);
}
public int compareTo(Variable variable) {
@ -198,7 +197,7 @@ final class ProcessEnvironment
}
public static Value valueOfQueryOnly(String str) {
return new Value(str, str.getBytes(StaticProperty.jnuCharset()));
return new Value(str, str.getBytes(JNU_CHARSET));
}
public static Value valueOf(String str) {
@ -207,7 +206,7 @@ final class ProcessEnvironment
}
public static Value valueOf(byte[] bytes) {
return new Value(new String(bytes, StaticProperty.jnuCharset()), bytes);
return new Value(new String(bytes, JNU_CHARSET), bytes);
}
public int compareTo(Value value) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
@ -69,6 +69,10 @@ final class ProcessImpl extends Process {
// Linux platforms support a normal (non-forcible) kill signal.
static final boolean SUPPORTS_NORMAL_TERMINATION = true;
// Cache for JNU Charset. The encoding name is guaranteed
// to be supported in this environment.
static final Charset JNU_CHARSET = Charset.forName(StaticProperty.jnuEncoding());
private final int pid;
private final ProcessHandleImpl processHandle;
private int exitcode;
@ -114,11 +118,11 @@ final class ProcessImpl extends Process {
LaunchMechanism lm;
if (s == null) {
lm = defaultLaunchMechanism;
s = lm.name().toLowerCase(Locale.ENGLISH);
s = lm.name().toLowerCase(Locale.ROOT);
} else {
try {
lm = LaunchMechanism.valueOf(
s.toUpperCase(Locale.ENGLISH));
s.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException e) {
lm = null;
}
@ -152,7 +156,7 @@ final class ProcessImpl extends Process {
private static byte[] toCString(String s) {
if (s == null)
return null;
byte[] bytes = s.getBytes(StaticProperty.jnuCharset());
byte[] bytes = s.getBytes(JNU_CHARSET);
byte[] result = new byte[bytes.length + 1];
System.arraycopy(bytes, 0,
result, 0,
@ -176,7 +180,7 @@ final class ProcessImpl extends Process {
byte[][] args = new byte[cmdarray.length-1][];
int size = args.length; // For added NUL bytes
for (int i = 0; i < args.length; i++) {
args[i] = cmdarray[i+1].getBytes(StaticProperty.jnuCharset());
args[i] = cmdarray[i+1].getBytes(JNU_CHARSET);
size += args[i].length;
}
byte[] argBlock = new byte[size];