JDK-8173975 : Lookup::in should not allow target class be primitive or array class
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-02-06
  • Updated: 2020-02-04
  • Resolved: 2019-10-29
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 14
14 b21Fixed
Related Reports
CSR :  
Sub Tasks
JDK-8238458 :  
MethodHandles.privateLookupIn currently disallows the target lookup class be a primitive or array class. This is mildly inconsistent with Lookup::in where it is possible to create a lookup with a primitive or array class as the lookup class (although maybe with reduced access). This issue tracks re-examining this issue to see if privateLookupIn should be relaxed.
URL: https://hg.openjdk.java.net/jdk/jdk/rev/67a3f50b14ae User: mchung Date: 2019-10-29 19:52:16 +0000

Yes, that is a reasonable reading of the API, and also my original intention. I support this restriction.

MethodHandles::lookup produces a Lookup object on the caller class. I believe the original intent for a Lookup object whose lookup class is a non-array and non-primitive type and the access check is performed against two instance classes. VerifyAccess::isSamePackage prior to JDK-8207027 has an assert statement on non-array types. It's modified to support Lookup::accessClass to test if an array class is accessible to the lookup class. MethodHandles::privateLookupIn and Lookup::in produce a new Lookup object. I think they should not produce a Lookup object on an array type or primitive. I propose to make Lookup::in consistent with MethodHandles::privateLookupIn to throw IAE if the target class is an array type or primitive type.