JBR-3772 java/beans/PropertyEditor/TestFontClass.java: access denied ("java.util.PropertyPermission" "sun.awt.x11.trace" "read")

Instead of using System.getProperty() directly, wrap the call into
GetPropertyAction and use AccessController to execute it.

(cherry picked from commit 4fefc6244b)
This commit is contained in:
Maxim Kartashev
2021-09-15 12:18:34 +03:00
committed by jbrbot
parent 1e424ca317
commit 52547fb175
3 changed files with 12 additions and 6 deletions

View File

@@ -70,8 +70,10 @@ public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
private static final double debugScale;
static {
String uiScaleEnabledPropValue = System.getProperty("sun.java2d.uiScale.enabled", "true");
uiScaleEnabled = FontUtilities.isMacOSX ||
("true".equals(System.getProperty("sun.java2d.uiScale.enabled", "true")) &&
("true".equals(uiScaleEnabledPropValue) &&
(isWindows_8_1_orUpper() || FontUtilities.isLinux));
if (uiScaleEnabled && FontUtilities.isWindows) {

View File

@@ -182,7 +182,9 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
}
static {
final String trace = System.getProperty("sun.awt.x11.trace");
final GetPropertyAction gpa = new GetPropertyAction("sun.awt.x11.trace");
@SuppressWarnings("removal")
final String trace = AccessController.doPrivileged(gpa);
if (trace != null) {
int traceFlags = 0;
final StringTokenizer st = new StringTokenizer(trace, ",");

View File

@@ -1333,9 +1333,12 @@ static int getRemoteX11WorkaroundProperty() {
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jstring name = (*env)->NewStringUTF(env, WORKAROUND_PROPERTY_NAME);
CHECK_NULL_RETURN(name, ret);
jstring jPropValue = JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "getProperty",
"(Ljava/lang/String;)Ljava/lang/String;", name).l;
if (jPropValue != NULL) {
jobject jPropGetAction = JNU_NewObjectByName(env, "sun/security/action/GetPropertyAction", "(Ljava/lang/String;)V", name);
CHECK_NULL_RETURN(name, ret);
jboolean ignoreExc;
jstring jPropValue = JNU_CallStaticMethodByName(env, &ignoreExc, "java/security/AccessController", "doPrivileged",
"(Ljava/security/PrivilegedAction;)Ljava/lang/Object;", jPropGetAction).l;
if (jPropValue != NULL && JNU_IsInstanceOfByName(env, jPropValue, "java/lang/String")) {
const char * utf8string = (*env)->GetStringUTFChars(env, jPropValue, NULL);
if (utf8string != NULL) {
if (strcmp(utf8string, "true") == 0) {
@@ -1346,7 +1349,6 @@ static int getRemoteX11WorkaroundProperty() {
}
(*env)->ReleaseStringUTFChars(env, jPropValue, utf8string);
}
(*env)->DeleteLocalRef(env, name);
return ret;
}