-
Bug
-
Resolution: Fixed
-
P3
-
9
-
b20
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.
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.
- csr for
-
JDK-8240338 Lookup::defineClass should link the class to match the specification
-
- Closed
-
- relates to
-
JDK-8238358 Implementation of JEP 371: Hidden Classes
-
- Resolved
-