Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

mlchung
Copy link
Member

@mlchung mlchung commented Sep 13, 2023

This PR improves IllegalAccessException message thrown by Lookup::findXXX APIs if the method's variable arity modifier bit is set and asVarargsCollector fails. It will include the exception message thrown by asVarargsCollector`.

The exception message looks like this:

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

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8267509: Improve IllegalAccessException message to include the cause of the exception (Enhancement - P4)

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 13, 2023

👋 Welcome back mchung! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 13, 2023
@openjdk
Copy link

openjdk bot commented Sep 13, 2023

@mlchung The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 13, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 13, 2023

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());
Copy link
Member

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.

Copy link
Member Author

@mlchung mlchung Sep 13, 2023

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

@naotoj
Copy link
Member

naotoj commented Oct 4, 2023

Would it be helpful if we call IllegalAccessException.initCause(IllegalArgumentException) before throwing it?

@mlchung
Copy link
Member Author

mlchung commented Oct 4, 2023

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.

@openjdk
Copy link

openjdk bot commented Oct 4, 2023

@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:

8267509: Improve IllegalAccessException message to include the cause of the exception

Reviewed-by: liach, naoto

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 master branch:

  • ddacf92: 8305765: CompressedClassPointers.java is unreliable due to ASLR
  • 4195246: 8317354: Serial: Move DirtyCardToOopClosure to gc/serial folder
  • 0a3a925: 8316414: C2: large byte array clone triggers "failed: malformed control flow" assertion failure on linux-x86
  • b0d6c84: 8316396: Endless loop in C2 compilation triggered by AddNode::IdealIL
  • a8549b6: 8280120: [IR Framework] Add attribute to @ir to enable/disable IR matching based on the architecture
  • 9718f49: 8317452: [JVMCI] Export symbols used by lightweight locking to JVMCI compilers.
  • 0d4de8a: 8316971: Add Lint warning for restricted method calls
  • d4c904d: 8317294: Classloading throws exceptions over already pending exceptions
  • 48f1a92: 8316679: C2 SuperWord: wrong result, load should not be moved before store if not comparable
  • 0b0f8b5: 8219652: [aix] Tests failing with JNI attach problems.
  • ... and 306 more: https://git.openjdk.org/jdk/compare/a9679acd5c85b88afe827dc55dbe9a78b00c8918...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 4, 2023
@mlchung
Copy link
Member Author

mlchung commented Oct 4, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Oct 4, 2023

Going to push as commit 36314a9.
Since your change was applied there have been 316 commits pushed to the master branch:

  • ddacf92: 8305765: CompressedClassPointers.java is unreliable due to ASLR
  • 4195246: 8317354: Serial: Move DirtyCardToOopClosure to gc/serial folder
  • 0a3a925: 8316414: C2: large byte array clone triggers "failed: malformed control flow" assertion failure on linux-x86
  • b0d6c84: 8316396: Endless loop in C2 compilation triggered by AddNode::IdealIL
  • a8549b6: 8280120: [IR Framework] Add attribute to @ir to enable/disable IR matching based on the architecture
  • 9718f49: 8317452: [JVMCI] Export symbols used by lightweight locking to JVMCI compilers.
  • 0d4de8a: 8316971: Add Lint warning for restricted method calls
  • d4c904d: 8317294: Classloading throws exceptions over already pending exceptions
  • 48f1a92: 8316679: C2 SuperWord: wrong result, load should not be moved before store if not comparable
  • 0b0f8b5: 8219652: [aix] Tests failing with JNI attach problems.
  • ... and 306 more: https://git.openjdk.org/jdk/compare/a9679acd5c85b88afe827dc55dbe9a78b00c8918...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 4, 2023
@openjdk openjdk bot closed this Oct 4, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 4, 2023
@openjdk
Copy link

openjdk bot commented Oct 4, 2023

@mlchung Pushed as commit 36314a9.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@mlchung mlchung deleted the JDK-8267509 branch October 4, 2023 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants