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

Enhance error message when IncompatibleClassChangeError is thrown for sealed class loading failures

XMLWordPrintable

    • b03

      java.lang.IncompatibleClassChangeError is thrown when using custom class loader to load sealed child class by overwriting ClassLoader::defineClass. The error message is not clearly showing what the root cause is. See below.

      Run the attached sample code with Java 17, following error message is thrown,
      Exception in thread "main" java.lang.IncompatibleClassChangeError: class samplecode.SealedClass cannot inherit from sealed class samplecode.SealedClassUpperClass
      at java.base/java.lang.ClassLoader.defineClass1(Native Method)
      at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
      at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:874)
      at samplecode.SealedClassTest2$CustomClassLoader.findClass(SealedClassTest2.java:35)
      at samplecode.SealedClassTest2.main(SealedClassTest2.java:16)

            dholmes David Holmes
            wxiao Weibing Xiao
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: