JDK-8234729 : Javac should eagerly change code generation for method references to avert IllegalAccessError in future.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 14
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2019-11-25
  • Updated: 2020-06-18
  • Resolved: 2019-11-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14
14 b25Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
In the valhalla nestmates branch, lambda metafactory has undergone some evolution and the lambda proxy class is no longer created with `Unsafe::defineAnonymousClass` but rather with `Lookup::defineHiddenClass`.

The lambda proxy class is created as a hidden nestmate of the target class and it follows the proper access control checks.

The older Unsafe::defineAnonymousClass mechanism was somewhat lenient/permissive in access control checks and was granting access to a protected member in its super class in a different package of the host class. The new Lookup::defineHiddenClass conforms to the proper access control checks. As a result, the lambda proxy class is a nestmate of the target class and it gets IAE when invoking super::protectedMember where its super class is in a different package from nestmate class.

This problem was addressed in the nestmates branch by JDK-8227415 which basically converts the method reference into lambda expression. 

(Javac's needsConversionToLambda() infrastructure is used fold method references into lambdas to workaround various quirks/limitations/defects in the lambda metafactory/bootstrap mechanism. It just chooses an alternate code generation scheme that does not triggers those quirks/limitations/defects.)

In the new code generation scheme where a method reference is converted into a lambda expression, there is no violation of any access control rule, since lambda proxy invokes a "bridge" method that is in the same package as the lambda proxy class.

There is an incompatibility concern when LambdaMetaFactory migrates to use hidden classes due to the missing access bridge to access the protected method reference declared in super class in different package.

For classes compiled with existing releases, IllegalAccessError will be thrown for the scenario discussed when the application is run under a VM that uses Lookup::defineHiddenClass

Hidden classes are expected in a release post 14, it would be prudent on the part of javac to eagerly alter the code generation for the concerned scenario, so as allow smoother migration of code to a hidden classes enabled VM
Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/d9a3bddcffcc User: sadayapalam Date: 2019-11-26 05:45:44 +0000
26-11-2019

Basically we need to bring forward the fix from the nestmates branch to jdk/jdk to eagerly change the code generation scheme so that code compiled with the "current" release will just run fine on a hidden class enabled VM whenever that is released. Otherwise, IAE would result and would force a recompile of the program.
25-11-2019