Skip to content
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

8270056: Generated lambda class can not access protected static method of target class #4714

Closed
wants to merge 3 commits into from

Conversation

@kelthuzadx
Copy link
Member

@kelthuzadx kelthuzadx commented Jul 8, 2021

Generated lambda class can not access protected static method of the target class. The following exception is thrown when executing the attached reproducible program:

Exception in thread "main" java.lang.IllegalAccessError: class AccessProtectedStaticMethodFromSuper$B$$Lambda$15/0x0000000800b8ea48 tried to access protected method 'void AccessProtectedStaticMethodFromSuper$A.func()' (AccessProtectedStaticMethodFromSuper$B$$Lambda$15/0x0000000800b8ea48 is in unnamed module of loader AccessProtectedStaticMethodFromSuper$1Loader @71dac704; AccessProtectedStaticMethodFromSuper$A is in unnamed module of loader AccessProtectedStaticMethodFromSuper$1Loader @39ed3c8d)
	at AccessProtectedStaticMethodFromSuper.main(AccessProtectedStaticMethodFromSuper.java:51)

This issue is similar to JDK-8254975(#767) with slight differences: generated lambda proxy calls static protected method rather than protected member method.

The proposed fix 1) tries to use MethodHandle instead of invoking forwardee directly(since the lambda class has no access to the resolved method) and 2) does not force accepting an implClass as the first argument when invoking a static method.

Testing:

  • test/jdk/java/ with release mode
  • presubmit tests

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8270056: Generated lambda class can not access protected static method of target class

Reviewers

Contributors

  • NekoCaffeine <nekocaffeine@qq.com>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4714/head:pull/4714
$ git checkout pull/4714

Update a local copy of the PR:
$ git checkout pull/4714
$ git pull https://git.openjdk.java.net/jdk pull/4714/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4714

View PR using the GUI difftool:
$ git pr show -t 4714

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4714.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Jul 8, 2021

👋 Welcome back yyang! 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.

Loading

@openjdk openjdk bot added the rfr label Jul 8, 2021
@kelthuzadx kelthuzadx changed the title 8270056: Generated lambda proxy can not access protected static method of target class 8270056: Generated lambda class can not access protected static method of target class Jul 8, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jul 8, 2021

@kelthuzadx 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.

Loading

@openjdk openjdk bot added the core-libs label Jul 8, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Jul 8, 2021

Webrevs

Loading

Copy link
Member

@mlchung mlchung left a comment

Good catch. The fix looks good. It should check if the target class (not implClass) and the declaring class of the implementation's method handle are in the same package if it's protected.

I prefer to add the new test case in the existing test test/jdk/java/lang/invoke/lambda/superProtectedMethod/SuperMethodTest.java. The test's name may be made clearer to rename to ProtectedMethodInOtherPackage (something like that)

Loading

Copy link
Member

@mlchung mlchung left a comment

The class name needs to be renamed as well. Also the classname in the @run command.

Loading

@@ -101,6 +101,30 @@ public static void splitPackage() throws Throwable {
((Runnable) get.invoke(b)).run();
}

@Test
public static void splitPackage1() throws Throwable {
Copy link
Member

@mlchung mlchung Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps the method name can be protectedStaticMethodInSplitPackage

Loading

Copy link
Member

@mlchung mlchung left a comment

Looks good.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jul 12, 2021

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

8270056: Generated lambda class can not access protected static method of target class

Co-authored-by: NekoCaffeine <nekocaffeine@qq.com>
Reviewed-by: mchung

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 140 new commits pushed to the master branch:

  • a4e5f08: 8267281: Call prepare_for_dynamic_dumping for jcmd dynamic_dump
  • 353e9c8: 8270320: JDK-8270110 committed invalid copyright headers
  • 7d2825e: 8270169: G1: Incorrect reference discovery MT degree in concurrent marking
  • 41a5eb4: 8270117: Broken jtreg link in "Building the JDK" page
  • 1aef372: 8266578: Disambiguate BigDecimal description of scale
  • 92ae6a5: 8244162: Additional opportunities to use NONCOPYABLE
  • 548bb31: 8270110: Shenandoah: Add test for JDK-8269661
  • c3a42ed: 8269878: Handle redundant reg-2-reg moves in X86 backend
  • 7cbb67a: 8267666: Add option to jcmd GC.heap_dump to use existing file
  • 8973867: 8269295: Verification time before/after young collection only covers parts of the verification
  • ... and 130 more: https://git.openjdk.java.net/jdk/compare/06d26208c5604c0c640eff4da94ef814c2ebebf0...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.

Loading

@openjdk openjdk bot added the ready label Jul 12, 2021
@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Jul 13, 2021

/contributor NekoCaffeine nekocaffeine@qq.com

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jul 13, 2021

@kelthuzadx Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

Loading

@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Jul 13, 2021

/contributor add NekoCaffeine nekocaffeine@qq.com

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jul 13, 2021

@kelthuzadx Could not parse NekoCaffeine nekocaffeine@qq.com as a valid contributor.
Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

Loading

@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Jul 13, 2021

/contributor add NekoCaffeine nekocaffeine@qq.com

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jul 13, 2021

@kelthuzadx
Contributor NekoCaffeine <nekocaffeine@qq.com> successfully added.

Loading

@kelthuzadx
Copy link
Member Author

@kelthuzadx kelthuzadx commented Jul 13, 2021

Thanks Mandy for review!

/integrate

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Jul 13, 2021

Going to push as commit 07e9052.
Since your change was applied there have been 141 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

Loading

@openjdk openjdk bot closed this Jul 13, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Jul 13, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Jul 13, 2021

@kelthuzadx Pushed as commit 07e9052.

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

Loading

@kelthuzadx kelthuzadx deleted the mh_bug branch Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants