Skip to content

Commit dd60065

Browse files
8342997: Remove use of System::getSecurityManager and SecurityManager from JavaFX
8342998: Remove all uses of AccessControlException 8342994: Remove security manager calls in com.sun.javafx.reflect Reviewed-by: angorya, lkostyra
1 parent b0e763c commit dd60065

33 files changed

+45
-901
lines changed

modules/javafx.base/src/main/java/com/sun/javafx/FXPermissions.java

-63
This file was deleted.

modules/javafx.base/src/main/java/com/sun/javafx/reflect/MethodUtil.java

+1-165
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,13 @@
2727

2828
import com.sun.javafx.SecurityUtil;
2929
import java.security.AllPermission;
30-
import java.security.AccessController;
3130
import java.security.PermissionCollection;
3231
import java.security.SecureClassLoader;
3332
import java.security.CodeSource;
3433
import java.io.InputStream;
3534
import java.io.IOException;
3635
import java.lang.reflect.Method;
3736
import java.lang.reflect.InvocationTargetException;
38-
import java.lang.reflect.Modifier;
39-
import java.util.Arrays;
40-
import java.util.HashMap;
41-
import java.util.Map;
4237

4338

4439
class Trampoline {
@@ -53,13 +48,11 @@ class Trampoline {
5348
}
5449
}
5550

56-
@SuppressWarnings("removal")
5751
private static void ensureInvocableMethod(Method m)
5852
throws InvocationTargetException
5953
{
6054
Class<?> clazz = m.getDeclaringClass();
61-
if (clazz.equals(AccessController.class) ||
62-
clazz.equals(Method.class) ||
55+
if (clazz.equals(Method.class) ||
6356
clazz.getName().startsWith("java.lang.invoke."))
6457
throw new InvocationTargetException(
6558
new UnsupportedOperationException("invocation not supported"));
@@ -102,163 +95,6 @@ public static Method[] getMethods(Class<?> cls) {
10295
return cls.getMethods();
10396
}
10497

105-
/*
106-
* Discover the public methods on public classes
107-
* and interfaces accessible to any caller by calling
108-
* Class.getMethods() and walking towards Object until
109-
* we're done.
110-
*/
111-
/*public*/
112-
@SuppressWarnings("removal")
113-
static Method[] getPublicMethods(Class<?> cls) {
114-
// compatibility for update release
115-
if (System.getSecurityManager() == null) {
116-
return cls.getMethods();
117-
}
118-
Map<Signature, Method> sigs = new HashMap<>();
119-
while (cls != null) {
120-
boolean done = getInternalPublicMethods(cls, sigs);
121-
if (done) {
122-
break;
123-
}
124-
getInterfaceMethods(cls, sigs);
125-
cls = cls.getSuperclass();
126-
}
127-
return sigs.values().toArray(new Method[sigs.size()]);
128-
}
129-
130-
/*
131-
* Process the immediate interfaces of this class or interface.
132-
*/
133-
private static void getInterfaceMethods(Class<?> cls,
134-
Map<Signature, Method> sigs) {
135-
Class<?>[] intfs = cls.getInterfaces();
136-
for (int i=0; i < intfs.length; i++) {
137-
Class<?> intf = intfs[i];
138-
boolean done = getInternalPublicMethods(intf, sigs);
139-
if (!done) {
140-
getInterfaceMethods(intf, sigs);
141-
}
142-
}
143-
}
144-
145-
/*
146-
*
147-
* Process the methods in this class or interface
148-
*/
149-
private static boolean getInternalPublicMethods(Class<?> cls,
150-
Map<Signature, Method> sigs) {
151-
Method[] methods = null;
152-
try {
153-
/*
154-
* This class or interface is non-public so we
155-
* can't use any of it's methods. Go back and
156-
* try again with a superclass or superinterface.
157-
*/
158-
if (!Modifier.isPublic(cls.getModifiers())) {
159-
return false;
160-
}
161-
if (!ReflectUtil.isPackageAccessible(cls)) {
162-
return false;
163-
}
164-
165-
methods = cls.getMethods();
166-
} catch (SecurityException se) {
167-
return false;
168-
}
169-
170-
/*
171-
* Check for inherited methods with non-public
172-
* declaring classes. They might override and hide
173-
* methods from their superclasses or
174-
* superinterfaces.
175-
*/
176-
boolean done = true;
177-
for (int i=0; i < methods.length; i++) {
178-
Class<?> dc = methods[i].getDeclaringClass();
179-
if (!Modifier.isPublic(dc.getModifiers())) {
180-
done = false;
181-
break;
182-
}
183-
}
184-
185-
if (done) {
186-
/*
187-
* We're done. Spray all the methods into
188-
* the list and then we're out of here.
189-
*/
190-
for (int i=0; i < methods.length; i++) {
191-
addMethod(sigs, methods[i]);
192-
}
193-
} else {
194-
/*
195-
* Simulate cls.getDeclaredMethods() by
196-
* stripping away inherited methods.
197-
*/
198-
for (int i=0; i < methods.length; i++) {
199-
Class<?> dc = methods[i].getDeclaringClass();
200-
if (cls.equals(dc)) {
201-
addMethod(sigs, methods[i]);
202-
}
203-
}
204-
}
205-
return done;
206-
}
207-
208-
private static void addMethod(Map<Signature, Method> sigs, Method method) {
209-
Signature signature = new Signature(method);
210-
if (!sigs.containsKey(signature)) {
211-
sigs.put(signature, method);
212-
} else if (!method.getDeclaringClass().isInterface()){
213-
/*
214-
* Superclasses beat interfaces.
215-
*/
216-
Method old = sigs.get(signature);
217-
if (old.getDeclaringClass().isInterface()) {
218-
sigs.put(signature, method);
219-
}
220-
}
221-
}
222-
223-
/**
224-
* A class that represents the unique elements of a method that will be a
225-
* key in the method cache.
226-
*/
227-
private static class Signature {
228-
private final String methodName;
229-
private final Class<?>[] argClasses;
230-
private final int hashCode;
231-
232-
Signature(Method m) {
233-
this.methodName = m.getName();
234-
this.argClasses = m.getParameterTypes();
235-
this.hashCode = methodName.hashCode() + Arrays.hashCode(argClasses);
236-
}
237-
238-
@Override public int hashCode() {
239-
return hashCode;
240-
}
241-
242-
@Override public boolean equals(Object o2) {
243-
if (this == o2) {
244-
return true;
245-
}
246-
Signature that = (Signature)o2;
247-
if (!(methodName.equals(that.methodName))) {
248-
return false;
249-
}
250-
if (argClasses.length != that.argClasses.length) {
251-
return false;
252-
}
253-
for (int i = 0; i < argClasses.length; i++) {
254-
if (!(argClasses[i] == that.argClasses[i])) {
255-
return false;
256-
}
257-
}
258-
return true;
259-
}
260-
}
261-
26298

26399
/*
264100
* Get the (unnamed) module of the trampoline class

modules/javafx.base/src/main/java/com/sun/javafx/reflect/ReflectUtil.java

-72
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,6 @@ private ReflectUtil() {
4747
* also check the package access on the proxy interfaces.
4848
*/
4949
public static void checkPackageAccess(Class<?> clazz) {
50-
@SuppressWarnings("removal")
51-
SecurityManager s = System.getSecurityManager();
52-
if (s != null) {
53-
privateCheckPackageAccess(s, clazz);
54-
}
55-
}
56-
57-
/**
58-
* NOTE: should only be called if a SecurityManager is installed
59-
*/
60-
private static void privateCheckPackageAccess(@SuppressWarnings("removal") SecurityManager s, Class<?> clazz) {
61-
while (clazz.isArray()) {
62-
clazz = clazz.getComponentType();
63-
}
64-
65-
String pkg = clazz.getPackageName();
66-
if (pkg != null && !pkg.isEmpty()) {
67-
s.checkPackageAccess(pkg);
68-
}
69-
70-
if (isNonPublicProxyClass(clazz)) {
71-
privateCheckProxyPackageAccess(s, clazz);
72-
}
7350
}
7451

7552
/**
@@ -79,58 +56,9 @@ private static void privateCheckPackageAccess(@SuppressWarnings("removal") Secur
7956
* the true caller (application).
8057
*/
8158
public static void checkPackageAccess(String name) {
82-
@SuppressWarnings("removal")
83-
SecurityManager s = System.getSecurityManager();
84-
if (s != null) {
85-
String cname = name.replace('/', '.');
86-
if (cname.startsWith("[")) {
87-
int b = cname.lastIndexOf('[') + 2;
88-
if (b > 1 && b < cname.length()) {
89-
cname = cname.substring(b);
90-
}
91-
}
92-
int i = cname.lastIndexOf('.');
93-
if (i != -1) {
94-
s.checkPackageAccess(cname.substring(0, i));
95-
}
96-
}
9759
}
9860

9961
public static boolean isPackageAccessible(Class<?> clazz) {
100-
try {
101-
checkPackageAccess(clazz);
102-
} catch (SecurityException e) {
103-
return false;
104-
}
10562
return true;
10663
}
107-
108-
/**
109-
* NOTE: should only be called if a SecurityManager is installed
110-
*/
111-
private static void privateCheckProxyPackageAccess(@SuppressWarnings("removal") SecurityManager s, Class<?> clazz) {
112-
// check proxy interfaces if the given class is a proxy class
113-
if (Proxy.isProxyClass(clazz)) {
114-
for (Class<?> intf : clazz.getInterfaces()) {
115-
privateCheckPackageAccess(s, intf);
116-
}
117-
}
118-
}
119-
120-
// Note that bytecode instrumentation tools may exclude 'sun.*'
121-
// classes but not generated proxy classes and so keep it in com.sun.*
122-
public static final String PROXY_PACKAGE = "com.sun.proxy";
123-
124-
/**
125-
* Test if the given class is a proxy class that implements
126-
* non-public interface. Such proxy class may be in a non-restricted
127-
* package that bypasses checkPackageAccess.
128-
*/
129-
public static boolean isNonPublicProxyClass(Class<?> cls) {
130-
if (!Proxy.isProxyClass(cls)) {
131-
return false;
132-
}
133-
String pkg = cls.getPackageName();
134-
return pkg == null || !pkg.startsWith(PROXY_PACKAGE);
135-
}
13664
}

0 commit comments

Comments
 (0)