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

(reflect) Exception from newInstance() not chained to cause.

XMLWordPrintable

    • b01
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.5.0_05"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      XP and Linux

      A DESCRIPTION OF THE PROBLEM :
      In Class.java, an InstantiationException is thrown when the constructor could not be found on a Class where newInstance() was called. When throwing this exception, the exception message is only the class name.

      1) The message should be more descriptive, as it is NO useful information is transmitted.

      2) The exception should be chained to the MethodNotFoundException so that the stacktrace contains the full details.

                  try {
      Class[] empty = {};
                      final Constructor<T> c = getConstructor0(empty, Member.DECLARED);
                      // Disable accessibility checks on the constructor
                      // since we have to do the security check here anyway
                      // (the stack depth is wrong for the Constructor's
                      // security check to work)
                      java.security.AccessController.doPrivileged
                          (new java.security.PrivilegedAction() {
                                  public Object run() {
                                      c.setAccessible(true);
                                      return null;
                                  }
                              });
                      cachedConstructor = c;
                  } catch (NoSuchMethodException e) {
                      throw new InstantiationException(getName());
                  }


      REPRODUCIBILITY :
      This bug can be reproduced always.

            darcy Joe Darcy
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: