Skip to content

Commit f79c724

Browse files
Merge from master
2 parents 96bbea0 + a1094f1 commit f79c724

File tree

18 files changed

+246
-44
lines changed

18 files changed

+246
-44
lines changed

build.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,9 +1581,6 @@ allprojects {
15811581

15821582
// Qualified exports needed by javafx.* modules (excluding javafx.swing)
15831583
def qualExportsCore = [
1584-
"--add-exports=java.base/sun.reflect.misc=javafx.base",
1585-
"--add-exports=java.base/sun.reflect.misc=javafx.fxml",
1586-
"--add-exports=java.base/sun.reflect.misc=javafx.web",
15871584
"--add-exports=java.base/sun.util.logging=javafx.base",
15881585
"--add-exports=java.base/sun.util.logging=javafx.controls",
15891586
"--add-exports=java.base/sun.util.logging=javafx.fxml",

dependencies/java.base/module-info.java.extra

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
* questions.
2424
*/
2525

26-
exports sun.reflect.misc to javafx.base;
27-
exports sun.reflect.misc to javafx.fxml;
28-
exports sun.reflect.misc to javafx.web;
2926
exports sun.util.logging to javafx.base;
3027
exports sun.util.logging to javafx.controls;
3128
exports sun.util.logging to javafx.fxml;

modules/javafx.base/src/main/java/com/sun/javafx/property/MethodHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,7 +30,7 @@
3030
import java.lang.reflect.Method;
3131
import java.security.AccessController;
3232
import java.security.PrivilegedAction;
33-
import sun.reflect.misc.ReflectUtil;
33+
import com.sun.javafx.reflect.ReflectUtil;
3434

3535
/**
3636
* Utility class to wrap method invocation.

modules/javafx.base/src/main/java/com/sun/javafx/property/PropertyReference.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,7 +33,7 @@
3333

3434
import javafx.beans.property.ReadOnlyProperty;
3535

36-
import sun.reflect.misc.ReflectUtil;
36+
import com.sun.javafx.reflect.ReflectUtil;
3737

3838
/**
3939
* A handle to a specific property defined on some {@link Bean}.

modules/javafx.base/src/main/java/com/sun/javafx/property/adapter/JavaBeanPropertyBuilderHelper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,7 @@
2626
package com.sun.javafx.property.adapter;
2727

2828
import java.lang.reflect.Method;
29-
30-
import sun.reflect.misc.ReflectUtil;
29+
import com.sun.javafx.reflect.ReflectUtil;
3130

3231
/**
3332
*/

modules/javafx.base/src/main/java/com/sun/javafx/property/adapter/ReadOnlyJavaBeanPropertyBuilderHelper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,8 +26,7 @@
2626
package com.sun.javafx.property.adapter;
2727

2828
import java.lang.reflect.Method;
29-
30-
import sun.reflect.misc.ReflectUtil;
29+
import com.sun.javafx.reflect.ReflectUtil;
3130

3231
/**
3332
*/

modules/javafx.base/src/main/java/com/sun/javafx/property/adapter/ReadOnlyPropertyDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,7 @@
3434
import java.lang.reflect.InvocationTargetException;
3535
import java.lang.reflect.Method;
3636

37-
import sun.reflect.misc.ReflectUtil;
37+
import com.sun.javafx.reflect.ReflectUtil;
3838

3939
import static java.util.Locale.ENGLISH;
4040

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package com.sun.javafx.reflect;
27+
28+
import java.lang.reflect.Constructor;
29+
30+
public final class ConstructorUtil {
31+
32+
private ConstructorUtil() {
33+
}
34+
35+
public static Constructor<?> getConstructor(Class<?> cls, Class<?>[] params)
36+
throws NoSuchMethodException {
37+
ReflectUtil.checkPackageAccess(cls);
38+
return cls.getConstructor(params);
39+
}
40+
41+
public static Constructor<?>[] getConstructors(Class<?> cls) {
42+
ReflectUtil.checkPackageAccess(cls);
43+
return cls.getConstructors();
44+
}
45+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package com.sun.javafx.reflect;
27+
28+
import java.lang.reflect.Field;
29+
30+
public final class FieldUtil {
31+
32+
private FieldUtil() {
33+
}
34+
35+
public static Field getField(Class<?> cls, String name)
36+
throws NoSuchFieldException {
37+
ReflectUtil.checkPackageAccess(cls);
38+
return cls.getField(name);
39+
}
40+
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,7 @@
4343
import java.util.Arrays;
4444
import java.util.HashMap;
4545
import java.util.Map;
46-
import sun.reflect.misc.ReflectUtil;
46+
import com.sun.javafx.reflect.ReflectUtil;
4747

4848

4949
class Trampoline {
@@ -89,15 +89,13 @@ private MethodUtil() {
8989
super();
9090
}
9191

92-
/*public*/
93-
static Method getMethod(Class<?> cls, String name, Class<?>[] args)
92+
public static Method getMethod(Class<?> cls, String name, Class<?>[] args)
9493
throws NoSuchMethodException {
9594
ReflectUtil.checkPackageAccess(cls);
9695
return cls.getMethod(name, args);
9796
}
9897

99-
/*public*/
100-
static Method[] getMethods(Class<?> cls) {
98+
public static Method[] getMethods(Class<?> cls) {
10199
ReflectUtil.checkPackageAccess(cls);
102100
return cls.getMethods();
103101
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
27+
package com.sun.javafx.reflect;
28+
29+
import java.lang.reflect.Proxy;
30+
31+
public final class ReflectUtil {
32+
33+
private ReflectUtil() {
34+
}
35+
36+
/**
37+
* Checks package access on the given class.
38+
*
39+
* If it is a {@link Proxy#isProxyClass(java.lang.Class)} that implements
40+
* a non-public interface (i.e. may be in a non-restricted package),
41+
* also check the package access on the proxy interfaces.
42+
*/
43+
public static void checkPackageAccess(Class<?> clazz) {
44+
SecurityManager s = System.getSecurityManager();
45+
if (s != null) {
46+
privateCheckPackageAccess(s, clazz);
47+
}
48+
}
49+
50+
/**
51+
* NOTE: should only be called if a SecurityManager is installed
52+
*/
53+
private static void privateCheckPackageAccess(SecurityManager s, Class<?> clazz) {
54+
while (clazz.isArray()) {
55+
clazz = clazz.getComponentType();
56+
}
57+
58+
String pkg = clazz.getPackageName();
59+
if (pkg != null && !pkg.isEmpty()) {
60+
s.checkPackageAccess(pkg);
61+
}
62+
63+
if (isNonPublicProxyClass(clazz)) {
64+
privateCheckProxyPackageAccess(s, clazz);
65+
}
66+
}
67+
68+
/**
69+
* Checks package access on the given classname.
70+
* This method is typically called when the Class instance is not
71+
* available and the caller attempts to load a class on behalf
72+
* the true caller (application).
73+
*/
74+
public static void checkPackageAccess(String name) {
75+
SecurityManager s = System.getSecurityManager();
76+
if (s != null) {
77+
String cname = name.replace('/', '.');
78+
if (cname.startsWith("[")) {
79+
int b = cname.lastIndexOf('[') + 2;
80+
if (b > 1 && b < cname.length()) {
81+
cname = cname.substring(b);
82+
}
83+
}
84+
int i = cname.lastIndexOf('.');
85+
if (i != -1) {
86+
s.checkPackageAccess(cname.substring(0, i));
87+
}
88+
}
89+
}
90+
91+
public static boolean isPackageAccessible(Class<?> clazz) {
92+
try {
93+
checkPackageAccess(clazz);
94+
} catch (SecurityException e) {
95+
return false;
96+
}
97+
return true;
98+
}
99+
100+
/**
101+
* NOTE: should only be called if a SecurityManager is installed
102+
*/
103+
private static void privateCheckProxyPackageAccess(SecurityManager s, Class<?> clazz) {
104+
// check proxy interfaces if the given class is a proxy class
105+
if (Proxy.isProxyClass(clazz)) {
106+
for (Class<?> intf : clazz.getInterfaces()) {
107+
privateCheckPackageAccess(s, intf);
108+
}
109+
}
110+
}
111+
112+
// Note that bytecode instrumentation tools may exclude 'sun.*'
113+
// classes but not generated proxy classes and so keep it in com.sun.*
114+
public static final String PROXY_PACKAGE = "com.sun.proxy";
115+
116+
/**
117+
* Test if the given class is a proxy class that implements
118+
* non-public interface. Such proxy class may be in a non-restricted
119+
* package that bypasses checkPackageAccess.
120+
*/
121+
public static boolean isNonPublicProxyClass(Class<?> cls) {
122+
if (!Proxy.isProxyClass(cls)) {
123+
return false;
124+
}
125+
String pkg = cls.getPackageName();
126+
return pkg == null || !pkg.startsWith(PROXY_PACKAGE);
127+
}
128+
}

modules/javafx.fxml/src/main/java/com/sun/javafx/fxml/BeanAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,9 +40,9 @@
4040
import java.security.PrivilegedAction;
4141

4242
import javafx.beans.value.ObservableValue;
43-
import sun.reflect.misc.FieldUtil;
44-
import sun.reflect.misc.MethodUtil;
45-
import sun.reflect.misc.ReflectUtil;
43+
import com.sun.javafx.reflect.FieldUtil;
44+
import com.sun.javafx.reflect.MethodUtil;
45+
import com.sun.javafx.reflect.ReflectUtil;
4646

4747
/**
4848
* Exposes Java Bean properties of an object via the {@link Map} interface.

modules/javafx.fxml/src/main/java/com/sun/javafx/fxml/MethodHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.lang.reflect.Method;
3131
import java.security.AccessController;
3232
import java.security.PrivilegedAction;
33-
import sun.reflect.misc.ReflectUtil;
33+
import com.sun.javafx.reflect.ReflectUtil;
3434

3535
/**
3636
* Utility class to wrap method invocation.

modules/javafx.fxml/src/main/java/com/sun/javafx/fxml/builder/ProxyBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -45,8 +45,8 @@
4545
import java.util.TreeSet;
4646
import javafx.beans.NamedArg;
4747
import javafx.util.Builder;
48-
import sun.reflect.misc.ConstructorUtil;
49-
import sun.reflect.misc.ReflectUtil;
48+
import com.sun.javafx.reflect.ConstructorUtil;
49+
import com.sun.javafx.reflect.ReflectUtil;
5050

5151
/**
5252
* Using this builder assumes that some of the constructors of desired class

0 commit comments

Comments
 (0)