Duplicate :
|
|
Relates :
|
|
Relates :
|
A DESCRIPTION OF THE PROBLEM : When compiling the attached class using the Java 21 compiler with the --release 8 flag and running it under a Java 8 environment, an exception is thrown during reflection on the constructor parameters of an inner class. The exception occurs because the Java 8 reflection implementation does not expect an empty parameter name in the constructor of the inner class. This issue is unexpected, as code compiled with --release 8 should be compatible with Java 8 runtime. REGRESSION : Last worked in version 17.0.12 STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Compile the following class using the Java 21 compiler with the --release 8 flag: javac --release 8 OuterClass.java 2. Run the compiled class under a Java 8 runtime: java OuterClass EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The program should print Done without throwing any exceptions. ACTUAL - Exception in thread "main" java.lang.reflect.MalformedParametersException: Invalid parameter name "" at java.lang.reflect.Executable.verifyParameters(Executable.java:386) at java.lang.reflect.Executable.privateGetParameters(Executable.java:416) at java.lang.reflect.Executable.getParameters(Executable.java:357) at OuterClass.main(OuterClass.java:14) ---------- BEGIN SOURCE ---------- public class OuterClass { public class InnerClass { } public static void main(String... args) { InnerClass.class.getConstructors()[0].getParameters(); System.out.println("Done"); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Use the Java 17 compiler or earlier when compiling the code if it needs to be executed with the Java 8 runtime. This avoids the issue of the MalformedParametersException, as older Java compilers handle reflection compatibility with Java 8 more consistently.
|