-
Enhancement
-
Resolution: Fixed
-
P4
-
17, 21, 24, 25
-
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)
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)
- relates to
-
JDK-8346208 InCompatibleClassChangeError triggered when using ClassLoader::defineClass to load sealed class
- Open
- links to
-
Commit(master) openjdk/jdk/45331091
-
Review(master) openjdk/jdk/22703