JDK-8150782 : findClass / accessClass throw unexpected exceptions
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-02-28
  • Updated: 2021-04-29
  • Resolved: 2016-03-13
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 9
9 b112Fixed
Related Reports
Relates :  
Relates :  
Description
There are several issues with MethodHandles.Lookup.findClass() and accessClass() after JEP 274 was integrated:

1. accessClass() doesn't throw IAE on lookup object when a private static nested class of the other class is passed as an argument;

2. the same problem with findClass();

3. findClass() throws ClassNotFoundException on publicLookup object when a private static nested class of the other class is passed as an argument.
Comments
Thanks, [~slukyanov]: Cases 1/2: lookup is MH.lookup, not public lookup; I agree with your assessment that this is not a bug given the bytecode shape as opposed to the source shape. Case 3: confirmed - public lookup uses the bootstrap class loader. I'll proceed with documentation changes as you suggested.
10-03-2016

On case 3 (publicLookup() and ClassNotFoundException). I'd suggest the following spec clarifications to smooth things with findClass() usage: - define what is "lookup context" and/or specify that findClass() uses the loader of lookup class - clarify that in() now changes the class loader, not only the access rights - a few changes in publicLookup javadoc: -- it uses bootstrap class loader and therefore only finds system classes -- choice of Object as lookup class is not pure convention anymore -- publicLookup().in(...) doesn't change access rights, but changes the loader
09-03-2016

> 1. accessClass() doesn't throw IAE on lookup object when a private static nested class of the other class is passed as an argument; > 2. the same problem with findClass(); That don't seem to be bugs. Language-level private static nested class becomes bytecode-level package-private class (since there are no private classes in class file format), so it can be accessed by a lookup of a class in the same package. > 3. findClass() throws ClassNotFoundException on publicLookup object when a private static nested class of the other class is passed as an argument. That also makes sense. It looks like publicLookup() uses bootstrap class loader (since Object is the lookup class), and bootstrap class loader can't load user-defined classes.
04-03-2016

The attached tarball contains tests that reproduce the issues.
28-02-2016