-
CSR
-
Resolution: Approved
-
P3
-
None
-
behavioral
-
low
-
-
Java API
-
SE
Summary
Lookup::in
throws IllegalArgumentException
if the target class is a primitive type, void or an array class.
Problem
The current spec of Lookup::in
allows to produce a Lookup object on a primitive type,
void or an array class which is against the original design that assumes the lookup class
of a Lookup object is never non-array and non-primitive class (method handle
lookup is as if a specified member is referenced via bytecode)
The static factory methods MethodHandles::lookup
, MethodHandles::privateLookupIn
never produce a Lookup object on primitive type, void or array class.
Solution
Change the spec of Lookup::in
to throw IllegalArgumentException
if requestedLookupClass
is a primitive type, void or array type.
An alternative would be that Lookup::in
returns a Lookup object
successfully but drop all lookup modes if requestedLookupClass
is
a primitive type, void or array type. This delays the failure point to method handle
lookup time. It makes it harder to diagnose if any existing code is depending
on the existing behavior.
It is expected that it's rare for existing code to call Lookup::in
on a
primitive type, void or array type. It'd be more helpful to throw IAE when a
bad requestLookupClass
argument is passed to Lookup::in
.
Specification
The spec of Lookup::in
method has the following new @throws IAE
:
+ * @throws IllegalArgumentException if {@code requestedLookupClass} is a primitive type or void or array class
@throw IAE
in the spec of MethodHandles::privateLookupIn
method is updated to explicitly call out void
:
- * @throws IllegalArgumentException if {@code targetClass} is a primitive type or array class
+ * @throws IllegalArgumentException if {@code targetClass} is a primitive type or void or array class
- csr of
-
JDK-8173975 Lookup::in should not allow target class be primitive or array class
-
- Resolved
-