JDK-8341145 : MalformedParametersException when using reflection on an inner class constructor
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 21,23,24
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2024-09-27
  • Updated: 2024-09-30
  • Resolved: 2024-09-29
Related Reports
Duplicate :  
Relates :  
Description
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.


Comments
This is an issue with release 8. It has been fixed in JDK-8058322.
29-09-2024

The observations on MacOS: JDK 21ea+20: Passed. JDK 21ea+21: Failed, MalformedParametersException thrown JDK 23: Failed. JDK 24ea+10: Failed.
29-09-2024