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

(reflect spec) Class.newInstance() @throws InstantiationException requires clarification

XMLWordPrintable

    • Fix Understood
    • generic
    • generic

      Name: bkR10012 Date: 06/01/2004


      The description of java.lang.Class.newInstance() says:
      "Throws:
         ...
         InstantiationException - if this Class represents an abstract class,
         an interface, an array class, a primitive type, or void; or if the
         class has no nullary constructor; or if the instantiation fails for
         some other reason."

      This sentence may be interpreted in different ways:
      1. All uncatched exceptions in <init> method should be wrapped/translated
      into InstantiationException.
      2. newInstance() throws InstantiationException only if instantiation
      fails BEFORE <init> method execution. All unchecked exceptions that get
      thrown by the <init> method will get passed back to the caller of
      Class.newInstance().

      The specification should be clarified. The sentence "or if the instantiation
      fails for some other reason" should be removed or reworded.

      Note, now the RI does not translate <init> exceptions into an
      InstantiationException.

      ======================================================================

            Unassigned Unassigned
            kuzsunw Kuz Kuz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: