JDK-8221642 : AccessibleObject::setAccessible throws NPE when invoked by JNI code with no java frame on stack
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2019-03-28
  • Updated: 2022-08-09
  • Resolved: 2022-02-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 b08Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Description
AccessibleObject::canAccess, setAccessible, trySetAccessible are @CS methods.  It may result in NPE when invoked by JNI code with no java frame on stack.  They should be examined and define the behavior.
Comments
Changeset: 9c0104b9 Author: Mandy Chung <mchung@openjdk.org> Date: 2022-02-01 00:09:35 +0000 URL: https://git.openjdk.java.net/jdk/commit/9c0104b9c96f012da1602f503f641824d78f4260
01-02-2022

It can be. But this bug could be considered to backport to older releases since I considered the spec change is a clarification. The implementation fix can be backport. For JDK-8177155, we can document which CS method already handles null caller and which one does not. We can create sub-tasks for the ones need investigation.
28-01-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7271 Date: 2022-01-28 17:50:19 +0000
28-01-2022

Should this be a sub-task of JDK-8177155?
28-01-2022

The spec of AccessibleObject has been updated via JDK-8221530 that JNI code with no Java class on the stack can only access members that are public and its declaring class is public and in a package that is unconditionally exported. The current implementation of AccessibleObject::setAccessible, trySetAccessible throws NPE if the caller is null: Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Class.getModule()" because "caller" is null at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:307) at java.base/java.lang.reflect.AccessibleObject.trySetAccessible(AccessibleObject.java:277)
27-01-2022