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

[lworld] Constructor::newInstance on abstract Object class throws InstantiationException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • repo-valhalla
    • repo-valhalla
    • core-libs

      JDK-8283573 made j.l.Object an abstract class. In order to prevent breaking existing code, the javac and the JVM perform intercept attempts to instantiate j.l.Object and substitute the Object with the java.lang.Identity class.

      Currently, when asking the Reflection API for an accessor to a the constructor of j.l.Object, the instance being returned is an InstantiationExceptionConstructorAccessorImpl. Instances of this class throw an InstantiationException on any attempt to instantiate the class they provide access to.

      To align the behavior of the Reflection API with the new semantic of the 'new' bytecode, the API should perform the same class substitution as the VM does.

      An example of the issue can be see in test java/beans/Introspector/OverriddenGenericSetter.java which fails with the following stack trace:

      java.lang.InstantiationException
      at java.base/jdk.internal.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
      at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
      at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)
      at OverriddenGenericSetter.testBehaviour(OverriddenGenericSetter.java:85)
      at OverriddenGenericSetter.main(OverriddenGenericSetter.java:65)
      at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
      at java.base/java.lang.reflect.Method.invoke(Method.java:578)
      at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
      at java.base/java.lang.Thread.run(Thread.java:833)

      JavaTest Message: Test threw exception: java.lang.InstantiationException

            mchung Mandy Chung (Inactive)
            fparain Frederic Parain
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: