JDK-8238195 : Lookup::defineClass should link the class to match the specification
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-01-29
  • Updated: 2020-04-27
  • Resolved: 2020-04-21
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 15
15 b20Fixed
Related Reports
CSR :  
Relates :  
Sub Tasks
JDK-8246791 :  
The spec of Lookup::defineClass throws LinkageError:
    LinkageError - if the class is malformed (ClassFormatError), cannot be verified (VerifyError), is already defined, or another linkage error occurs

However, JDK implementation never links the class.

Lookup::defineClass was added in JDK 9 as a public supported API to replace the calls to the protected ClassLoader::defineClass method which frameworks have been suppressing the language access check via setAccessible.

Framework libraries use this API to define a class that is generated dynamically (that cannot be found from the class loader) and soon after executes the newly created class.   We can hardly think of any use case that a class is dynamically generated and defined by calling `ClassLoader::defineClass` but never used and never linked (except a stress testing harness perhaps).

While ClassLoader::defineClass does not link a class, there are only a few frameworks migrating to use Lookup::defineClass.   I think the compatibility risk is not high if we fix the implementation to match the specification.   On the other hand, deferring linking might give more flexibility to the ordering of a set of inter-dependent classes to be defined.
URL: https://hg.openjdk.java.net/jdk/jdk/rev/4b50e4e03c8b User: mchung Date: 2020-04-21 14:11:47 +0000