-
Enhancement
-
Resolution: Fixed
-
P4
-
21, 22
-
b18
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8319210 | 21.0.2 | Aleksey Shipilev | P4 | Resolved | Fixed | b05 |
See report at http://mail.openjdk.java.net/pipermail/hotspot-dev/2021-May/052203.html
If a MethodHandles.Lookup is used to locate a MethodHandle for a varargs method whose last parameter is not an array an IllegalArgumentException will be thrown:
> java.lang.IllegalArgumentException: not an array type: int
> at java.base/java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(MethodHandleStatics.java:138)
> at java.base/java.lang.invoke.MethodHandle.spreadArrayChecks(MethodHandle.java:1066)
> at java.base/java.lang.invoke.MethodHandle.asCollectorChecks(MethodHandle.java:1259)
> at java.base/java.lang.invoke.MethodHandle.asVarargsCollector(MethodHandle.java:1427)
> at java.base/java.lang.invoke.MethodHandle.withVarargs(MethodHandle.java:1111)
> at java.base/java.lang.invoke.MethodHandle.setVarargs(MethodHandle.java:1634)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:3755)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethod(MethodHandles.java:3691)
> at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:2399)
This makes sense, however it seems that the exception is swallowed and instead a generic IllegalAccessException is thrown:
> Caused by: java.lang.IllegalAccessException: cannot make variable arity: package.Class.method(Object[],int)Object/invokeStatic
> at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:957)
> at java.base/java.lang.invoke.MethodHandle.setVarargs(MethodHandle.java:1636)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:3755)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethod(MethodHandles.java:3691)
> at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:2399)
It would probably be helpful to make the IllegalAccessException caused by the IllegalArgumentException, or at the very least add it as a suppressed exception.
Otherwise the only way to find the helpful exception here is through runtime debugging.
If a MethodHandles.Lookup is used to locate a MethodHandle for a varargs method whose last parameter is not an array an IllegalArgumentException will be thrown:
> java.lang.IllegalArgumentException: not an array type: int
> at java.base/java.lang.invoke.MethodHandleStatics.newIllegalArgumentException(MethodHandleStatics.java:138)
> at java.base/java.lang.invoke.MethodHandle.spreadArrayChecks(MethodHandle.java:1066)
> at java.base/java.lang.invoke.MethodHandle.asCollectorChecks(MethodHandle.java:1259)
> at java.base/java.lang.invoke.MethodHandle.asVarargsCollector(MethodHandle.java:1427)
> at java.base/java.lang.invoke.MethodHandle.withVarargs(MethodHandle.java:1111)
> at java.base/java.lang.invoke.MethodHandle.setVarargs(MethodHandle.java:1634)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:3755)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethod(MethodHandles.java:3691)
> at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:2399)
This makes sense, however it seems that the exception is swallowed and instead a generic IllegalAccessException is thrown:
> Caused by: java.lang.IllegalAccessException: cannot make variable arity: package.Class.method(Object[],int)Object/invokeStatic
> at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:957)
> at java.base/java.lang.invoke.MethodHandle.setVarargs(MethodHandle.java:1636)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:3755)
> at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethod(MethodHandles.java:3691)
> at java.base/java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:2399)
It would probably be helpful to make the IllegalAccessException caused by the IllegalArgumentException, or at the very least add it as a suppressed exception.
Otherwise the only way to find the helpful exception here is through runtime debugging.
- backported by
-
JDK-8319210 Improve IllegalAccessException message to include the cause of the exception
- Resolved