Skip to content
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

8342459: Remove calls to doPrivileged in javafx.base #1625

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
89 changes: 33 additions & 56 deletions modules/javafx.base/src/main/java/com/sun/javafx/PlatformUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package com.sun.javafx;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
Expand All @@ -38,11 +36,6 @@

public class PlatformUtil {

// NOTE: since this class can be initialized by application code in some
// cases, we must encapsulate all calls to System.getProperty("...") in
// a doPrivileged block except for standard JVM properties such as
// os.name, os.version, os.arch, java.vm.name, etc.

private static final String os = System.getProperty("os.name");
private static final String version = System.getProperty("os.version");
private static final boolean embedded;
Expand All @@ -53,30 +46,19 @@ public class PlatformUtil {
private static String javafxPlatform;

static {
@SuppressWarnings("removal")
String str1 = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("javafx.platform"));
javafxPlatform = str1;
javafxPlatform = System.getProperty("javafx.platform");

loadProperties();

@SuppressWarnings("removal")
boolean bool1 = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("com.sun.javafx.isEmbedded"));
embedded = bool1;

@SuppressWarnings("removal")
String str2 = AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("glass.platform", "").toLowerCase(Locale.ROOT));
embeddedType = str2;

@SuppressWarnings("removal")
boolean bool2 = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("use.egl"));
useEGL = bool2;
embedded = Boolean.getBoolean("com.sun.javafx.isEmbedded");
embeddedType = System.getProperty("glass.platform", "").toLowerCase(Locale.ROOT);
useEGL = Boolean.getBoolean("use.egl");

if (useEGL) {
@SuppressWarnings("removal")
boolean bool3 = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("doNativeComposite"));
doEGLCompositing = bool3;
} else
doEGLCompositing = Boolean.getBoolean("doNativeComposite");
} else {
doEGLCompositing = false;
}
}

private static final boolean ANDROID = "android".equals(javafxPlatform) || "Dalvik".equals(System.getProperty("java.vm.name"));
Expand Down Expand Up @@ -150,9 +132,7 @@ public static boolean useEGLWindowComposition() {
}

public static boolean useGLES2() {
@SuppressWarnings("removal")
String useGles2 =
AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty("use.gles2"));
String useGles2 = System.getProperty("use.gles2");
if ("true".equals(useGles2))
return true;
else
Expand Down Expand Up @@ -260,7 +240,6 @@ private static File getRTDir() {
}
}

@SuppressWarnings("removal")
private static void loadProperties() {
final String vmname = System.getProperty("java.vm.name");
final String arch = System.getProperty("os.arch");
Expand All @@ -270,34 +249,32 @@ private static void loadProperties() {
(vmname != null && vmname.indexOf("Embedded") > 0))) {
return;
}
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
final File rtDir = getRTDir();
final String propertyFilename = "javafx.platform.properties";
File rtProperties = new File(rtDir, propertyFilename);
// First look for javafx.platform.properties in the JavaFX runtime
// Then in the installation directory of the JRE
if (rtProperties.exists()) {
loadPropertiesFromFile(rtProperties);
return null;
}
String javaHome = System.getProperty("java.home");
File javaHomeProperties = new File(javaHome,
"lib" + File.separator
+ propertyFilename);
if (javaHomeProperties.exists()) {
loadPropertiesFromFile(javaHomeProperties);
return null;
}

String javafxRuntimePath = System.getProperty("javafx.runtime.path");
File javafxRuntimePathProperties = new File(javafxRuntimePath,
File.separator + propertyFilename);
if (javafxRuntimePathProperties.exists()) {
loadPropertiesFromFile(javafxRuntimePathProperties);
return null;
}
return null;
});
final File rtDir = getRTDir();
final String propertyFilename = "javafx.platform.properties";
File rtProperties = new File(rtDir, propertyFilename);
// First look for javafx.platform.properties in the JavaFX runtime
// Then in the installation directory of the JRE
if (rtProperties.exists()) {
loadPropertiesFromFile(rtProperties);
return;
}
String javaHome = System.getProperty("java.home");
File javaHomeProperties = new File(javaHome,
"lib" + File.separator
+ propertyFilename);
if (javaHomeProperties.exists()) {
loadPropertiesFromFile(javaHomeProperties);
return;
}

String javafxRuntimePath = System.getProperty("javafx.runtime.path");
File javafxRuntimePathProperties = new File(javafxRuntimePath,
File.separator + propertyFilename);
if (javafxRuntimePathProperties.exists()) {
loadPropertiesFromFile(javafxRuntimePathProperties);
return;
}
}

public static boolean isAndroid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

package com.sun.javafx.logging;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -54,15 +52,12 @@ class PrintLogger extends Logger {
* the threshold, then it is logged, otherwise an abbreviated representation including
* only the time of the pulse is logged.
*/
@SuppressWarnings("removal")
private static long THRESHOLD = AccessController.doPrivileged((PrivilegedAction<Integer>) () -> Integer.getInteger("javafx.pulseLogger.threshold", 17));
private static long THRESHOLD = Integer.getInteger("javafx.pulseLogger.threshold", 17);

/**
* Optionally exit after a given number of pulses
*/
@SuppressWarnings("removal")
private static final int EXIT_ON_PULSE =
AccessController.doPrivileged((PrivilegedAction<Integer>) () -> Integer.getInteger("javafx.pulseLogger.exitOnPulse", 0));
private static final int EXIT_ON_PULSE = Integer.getInteger("javafx.pulseLogger.exitOnPulse", 0);

/**
* We have a simple counter that keeps track of the current pulse number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -102,9 +100,8 @@ public static void newInput(String name) {
* @return true if the user requested pulse logging by setting the system
* property javafx.pulseLogger to true, false otherwise.
*/
@SuppressWarnings("removal")
public static boolean isPulseLoggingRequested() {
return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("javafx.pulseLogger"));
return Boolean.getBoolean("javafx.pulseLogger");
}

// Loading known loggers reflectively, in case an expected module isn't available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@
import com.sun.javafx.reflect.MethodUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import com.sun.javafx.reflect.ReflectUtil;

/**
* Utility class to wrap method invocation.
*/
public class MethodHelper {
@SuppressWarnings("removal")
private static final boolean logAccessErrors
= AccessController.doPrivileged((PrivilegedAction<Boolean>) ()
-> Boolean.getBoolean("sun.reflect.debugModuleAccessChecks"));
= Boolean.getBoolean("sun.reflect.debugModuleAccessChecks");

private static final Module trampolineModule = MethodUtil.getTrampolineModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,17 @@ public class Disposer implements Runnable {

static {
disposerInstance = new Disposer();

@SuppressWarnings("removal")
var dummy = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<>() {
@Override
public Object run() {
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
ThreadGroup tg = Thread.currentThread().getThreadGroup();
for (ThreadGroup tgn = tg;
tgn != null;
tg = tgn, tgn = tg.getParent());
Thread t =
new Thread(tg, disposerInstance, "Property Disposer");
t.setContextClassLoader(null);
t.setDaemon(true);
t.setPriority(Thread.MAX_PRIORITY);
t.start();
return null;
}
}
);
/* The thread must be a member of a thread group
* which will not get GCed before VM exit.
* Make its parent the top-level thread group.
*/
ThreadGroup tg = Thread.currentThread().getThreadGroup();
for (ThreadGroup tgn = tg; tgn != null; tg = tgn, tgn = tg.getParent());
Thread t = new Thread(tg, disposerInstance, "Property Disposer");
t.setContextClassLoader(null);
t.setDaemon(true);
t.setPriority(Thread.MAX_PRIORITY);
t.start();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.security.AccessController;
import java.security.PermissionCollection;
import java.security.SecureClassLoader;
import java.security.PrivilegedExceptionAction;
import java.security.CodeSource;
import java.io.InputStream;
import java.io.IOException;
Expand Down Expand Up @@ -288,22 +287,15 @@ public static Object invoke(Method m, Object obj, Object[] params)
}
}

@SuppressWarnings("removal")
private static Method getTrampoline() {
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Method>() {
@Override
public Method run() throws Exception {
Class<?> t = getTrampolineClass();
Class<?>[] types = {
Method.class, Object.class, Object[].class
};
Method b = t.getDeclaredMethod("invoke", types);
b.setAccessible(true);
return b;
}
});
Class<?> t = getTrampolineClass();
Class<?>[] types = {
Method.class, Object.class, Object[].class
};
Method b = t.getDeclaredMethod("invoke", types);
b.setAccessible(true);
return b;
} catch (Exception e) {
throw new InternalError("bouncer cannot be found", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove the now-unused field private final AccessControlContext acc, which will also let you remove the AccessControlContext and AccessController. Alternatively, I will remove them as part of JDK-8342993.

This comment applies to all of the JavaBeanXXXProperty classes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Kevin, The variable acc and related 2 imports are now removed in commit.


/**
* A {@code JavaBeanBooleanProperty} provides an adapter between a regular
Expand Down Expand Up @@ -113,18 +112,15 @@ public final class JavaBeanBooleanProperty extends BooleanProperty implements Ja
* property throws an {@code IllegalAccessException} or an
* {@code InvocationTargetException}.
*/
@SuppressWarnings("removal")
@Override
public boolean get() {
return AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
try {
return (Boolean)MethodHelper.invoke(descriptor.getGetter(), getBean(), (Object[])null);
} catch (IllegalAccessException e) {
throw new UndeclaredThrowableException(e);
} catch (InvocationTargetException e) {
throw new UndeclaredThrowableException(e);
}
}, acc);
try {
return (Boolean)MethodHelper.invoke(descriptor.getGetter(), getBean(), (Object[])null);
} catch (IllegalAccessException e) {
throw new UndeclaredThrowableException(e);
} catch (InvocationTargetException e) {
throw new UndeclaredThrowableException(e);
}
}

/**
Expand All @@ -134,24 +130,19 @@ public boolean get() {
* property throws an {@code IllegalAccessException} or an
* {@code InvocationTargetException}.
*/
@SuppressWarnings("removal")
@Override
public void set(final boolean value) {
if (isBound()) {
throw new RuntimeException("A bound value cannot be set.");
}

AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
MethodHelper.invoke(descriptor.getSetter(), getBean(), new Object[] {value});
ExpressionHelper.fireValueChangedEvent(helper);
} catch (IllegalAccessException e) {
throw new UndeclaredThrowableException(e);
} catch (InvocationTargetException e) {
throw new UndeclaredThrowableException(e);
}
return null;
}, acc);
try {
MethodHelper.invoke(descriptor.getSetter(), getBean(), new Object[] {value});
ExpressionHelper.fireValueChangedEvent(helper);
} catch (IllegalAccessException e) {
throw new UndeclaredThrowableException(e);
} catch (InvocationTargetException e) {
throw new UndeclaredThrowableException(e);
}
}

/**
Expand Down
Loading