-
Bug
-
Resolution: Fixed
-
P2
-
18
-
b22
-
b26
-
x86_64
-
linux
-
Verified
In JDK17 as well as JDK18-18-ea+20, when one called `Field#set()` on a static field with an argument of invalid type, it used to throw an {{IllegalArgumentException}}.
In JDK18-ea+23 and JDK18-ea+24, it throws a {{NullPointerException}}:
{noformat}
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
at java.base/jdk.internal.reflect.MethodHandleObjectFieldAccessorImpl.set(MethodHandleObjectFieldAccessorImpl.java:114)
at java.base/java.lang.reflect.Field.set(Field.java:818)
at org.hibernate.jdk.playground.JavaReflectTest.lambda$staticField_invalidArgumentType$0(JavaReflectTest.java:16)
at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:55)
... 68 more
{noformat}
It seems the NPE is caused by new code expecting the "self" argument to be non-null when building the {{IllegalArgumentException}}. But for static fields, "self" is always {{null}}.
Reproducer:
* Clone https://github.com/yrodiere/jdk-playground.git
* Switch to branch {{java-reflect-npe}}
* Using JDK17, run {{./mvw clean test}} => No problem
* Using JDK18-ea+23, run {{./mvw clean test}} => Test failure
This bug was discovered by running the Hibernate ORM test suite on JDK 18 as part of the [OpenJDK Quality Outreach program|https://wiki.openjdk.java.net/display/quality/Quality+Outreach].
In JDK18-ea+23 and JDK18-ea+24, it throws a {{NullPointerException}}:
{noformat}
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
at java.base/jdk.internal.reflect.MethodHandleObjectFieldAccessorImpl.set(MethodHandleObjectFieldAccessorImpl.java:114)
at java.base/java.lang.reflect.Field.set(Field.java:818)
at org.hibernate.jdk.playground.JavaReflectTest.lambda$staticField_invalidArgumentType$0(JavaReflectTest.java:16)
at org.junit.jupiter.api.AssertThrows.assertThrows(AssertThrows.java:55)
... 68 more
{noformat}
It seems the NPE is caused by new code expecting the "self" argument to be non-null when building the {{IllegalArgumentException}}. But for static fields, "self" is always {{null}}.
Reproducer:
* Clone https://github.com/yrodiere/jdk-playground.git
* Switch to branch {{java-reflect-npe}}
* Using JDK17, run {{./mvw clean test}} => No problem
* Using JDK18-ea+23, run {{./mvw clean test}} => Test failure
This bug was discovered by running the Hibernate ORM test suite on JDK 18 as part of the [OpenJDK Quality Outreach program|https://wiki.openjdk.java.net/display/quality/Quality+Outreach].
- duplicates
-
JDK-8277510 Refactored reflection throws null pointer when setting unassignable type on static field
-
- Closed
-