-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8267509: Improve IllegalAccessException message to include the cause of the exception #15698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back mchung! A progress list of the required criteria for merging this PR into |
Webrevs
|
@@ -1719,7 +1719,7 @@ MethodHandle setVarargs(MemberName member) throws IllegalAccessException { | |||
try { | |||
return this.withVarargs(true); | |||
} catch (IllegalArgumentException ex) { | |||
throw member.makeAccessException("cannot make variable arity", null); | |||
throw new IllegalAccessException("cannot make variable arity: " + this + " because " + ex.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
or
java.lang.IllegalAccessException: cannot make variable arity: MyClass.m(Object[],int)void/invokeStatic does not have a trailing array parameter
Would it be helpful if we call |
It's a user error. The exception message makes it clear for the users what's wrong with the requested method. The cause's stacktrace is less relevant to them. |
@mlchung This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 316 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
/integrate |
Going to push as commit 36314a9.
Your commit was automatically rebased without conflicts. |
This PR improves IllegalAccessException message thrown by
Lookup::findXXX
APIs if the method's variable arity modifier bit is set andasVarargsCollector
fails. It will include the exception message thrown by asVarargsCollector`.The exception message looks like this:
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15698/head:pull/15698
$ git checkout pull/15698
Update a local copy of the PR:
$ git checkout pull/15698
$ git pull https://git.openjdk.org/jdk.git pull/15698/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15698
View PR using the GUI difftool:
$ git pr show -t 15698
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15698.diff
Webrev
Link to Webrev Comment