Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8238195

Lookup::defineClass should link the class to match the specification

    XMLWordPrintable

Details

    Description

      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.

      Attachments

        Issue Links

          There are no Sub-Tasks for this issue.

          Activity

            People

              mchung Mandy Chung
              mchung Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: