RFR: 8267509: Improve IllegalAccessException message to include the cause of the exception [v2]

Mandy Chung mchung at openjdk.org
Wed Sep 13 16:34:41 UTC 2023


On Wed, 13 Sep 2023 05:08:58 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Mandy Chung has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   use member (not method handle)
>
> src/java.base/share/classes/java/lang/invoke/MethodHandle.java line 1722:
> 
>> 1720:             return this.withVarargs(true);
>> 1721:         } catch (IllegalArgumentException ex) {
>> 1722:             throw new IllegalAccessException("cannot make variable arity: " + this + " because " + ex.getMessage());
> 
> This now drops the member information (owner and name) from the message. Is that intended?
> 
> In addition, the original message appears to include the method type, which can be used to diagnose why varargs is not possible (not an array for trailing parameter). I fail to see what extra information this patch offers that actually makes debugging easier as claimed in the JBS issue.

Good catch.  It's not intended.  Fixed.

I think in general it would be useful to make it clear in the exception message of the reason especially for those who are new in using method handles.  Looking it again, it can simply hardcode the message (more friendly than IAE exception message):


java.lang.IllegalAccessException: cannot make variable arity: MyClass.m(Object[],int)void/invokeStatic because not an array type: int

vs

java.lang.IllegalAccessException: cannot make variable arity: trailing parameter type is not an array type: MyClass.m(Object[],int)void/invokeStatic

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15698#discussion_r1324780782


More information about the core-libs-dev mailing list