JDK-8364145 : Constructor.newInstance missing error when invoked against inner class
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 25,26
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-07-27
  • Updated: 2025-07-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26Unresolved
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 11; java -version:
```
openjdk version "25-ea" 2025-09-16
OpenJDK Runtime Environment (build 25-ea+33-3475)
OpenJDK 64-Bit Server VM (build 25-ea+33-3475, mixed mode, sharing)
```

A DESCRIPTION OF THE PROBLEM :
In JDK 24, the inner class is created. In JDK 25, it throws `java.lang.reflect.InvocationTargetException` with `null`, non-descriptive message.

Sample code:
```
import java.lang.reflect.Constructor;
import java.lang.reflect.Parameter;
import java.util.Arrays;

public class Test {
    public class Pojo {
        public String name;
    }

    public static void main(String[] _a) {
        System.out.println("Pojo: " + newup(Pojo.class));
    }

    public static <T> Object newup(Class<T> className) {
        try { return invoke(className.getConstructors()[0]); }
        catch (Throwable e) { return "ex: " + e.getMessage(); }
    }

    public static <T> T invoke(Constructor<T> ctor) throws Throwable {
        var params = Arrays.stream(ctor.getParameters()).map(Test::typeDefaultValue).toArray();
        @SuppressWarnings("unchecked")
        T t = (T) ctor.newInstance(params);
        return t;
    }

    public static Object typeDefaultValue(Parameter parameter) {
        var type = parameter.getType();
        if (!type.isPrimitive()) return null;
        if (type.equals(boolean.class))  return false;
        return 0;
    }
}
```



Comments
[~tongwan] Can you ask the submitter about the real-world use case of this bug, for example, is the submitter using a serialization library that calls constructors? In particular, I hope you can suggest my proposed workaround (declare the inner class as static nested class instead) and see if that solves the real-world problem.
28-07-2025

A workaround for such a problem would be to declare this Pojo as static, making it a nested class instead of an inner class. The nature of inner class where it requires a constructor argument (and often an implementation-specific field) makes them unsuitable for pojos. Note that code compiled with javac before 24 will continue to run. It is only with javac 25 that such code will crash, similar to this: Test test = null; Pojo pojo = test.new Pojo();
28-07-2025

See change to javac in JDK-8164714 and the corresponding release note.
27-07-2025

The observations on Windows 11: JDK 25ea+15: Passed. JDK 25ea+16: Failed, null returned. Impact -> H (Regression) Likelihood -> L (Early access release) Workaround -> M (Somewhere in-between the extremes) Priority -> P3
27-07-2025