Fix proposal: JDK-8219378 NPE in ReflectionFactory.newMethodAccessor when langReflectAccess not initialized
Mandy Chung
mandy.chung at oracle.com
Mon Feb 25 21:13:31 UTC 2019
Hi Andrew,
I think initializing LangReflectAccess in AccessibleObject
is a better fix. Besides moving clinit to AccessibleObject,
ReflectionFactory::langReflectAccess can simply assert
if langReflectAccess is non-null. Attached is the patch
that you can reference.
We should do more testing to shake out any issue. Can you
run jdk-submit?
Mandy
On 2/25/19 7:00 AM, Andrew Leonard wrote:
> Hi Mandy,
> I can confirm "just" moving the clinit code into AccessibleObject does
> resolve the J9 issue as well, without changing ReflectionFactory...
> What's your thoughts?
> Thanks
> Andrew
-------------- next part --------------
--- old/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java 2019-02-25 11:21:24.000000000 -0800
+++ new/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java 2019-02-25 11:21:23.000000000 -0800
@@ -75,6 +75,16 @@
*/
public class AccessibleObject implements AnnotatedElement {
+ /*
+ * Bootstrapping protocol between java.lang and java.lang.reflect
+ * packages
+ */
+ static {
+ ReflectionFactory factory = AccessController.doPrivileged(
+ new ReflectionFactory.GetReflectionFactoryAction());
+ factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
+ }
+
static void checkPermission() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
--- old/src/java.base/share/classes/java/lang/reflect/Modifier.java 2019-02-25 11:21:25.000000000 -0800
+++ new/src/java.base/share/classes/java/lang/reflect/Modifier.java 2019-02-25 11:21:24.000000000 -0800
@@ -47,16 +47,6 @@
*/
public class Modifier {
- /*
- * Bootstrapping protocol between java.lang and java.lang.reflect
- * packages
- */
- static {
- ReflectionFactory factory = AccessController.doPrivileged(
- new ReflectionFactory.GetReflectionFactoryAction());
- factory.setLangReflectAccess(new java.lang.reflect.ReflectAccess());
- }
-
/**
* Return {@code true} if the integer argument includes the
* {@code public} modifier, {@code false} otherwise.
--- old/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java 2019-02-25 11:21:26.000000000 -0800
+++ new/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java 2019-02-25 11:21:25.000000000 -0800
@@ -726,13 +726,7 @@
}
private static LangReflectAccess langReflectAccess() {
- if (langReflectAccess == null) {
- // Call a static method to get class java.lang.reflect.Modifier
- // initialized. Its static initializer will cause
- // setLangReflectAccess() to be called from the context of the
- // java.lang.reflect package.
- Modifier.isPublic(Modifier.PUBLIC);
- }
+ assert langReflectAccess != null;
return langReflectAccess;
}
More information about the core-libs-dev
mailing list