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

java.lang.Class.forName() should provide actual reason of loading failures.

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      sparc
    • OS:
      solaris_2.4
    • Verification:
      Not verified

      Description



      Name: akC45999 Date: 03/12/98



      The description of java.lang.Class.forName() reads:

      Given the fully-qualified name for a class or interface, this method attempts
      to locate, load and link the class. If it succeeds, returns the Class object
      representing the class. If it fails, the method throws a ClassNotFoundException.


      Problem:

        Loading and linking may fail due to a number of reasons.
      Each such reason has corresponding exception (usually sublclass of LinkageError).
      But if Class.forName() throws ClassNotFoundException, the reason remains unknown
      to the calling program. This make debugging much harder.

      Proposed API change:

         Add a method getLoadingException() to the class ClassNotFoundException
      to return the actual exception thrown during loading and linking.

      This is similiar to
         java.lang.reflect.InvocationTargetException.getTargetException()

      used in java.lang reflect package to solve similiar problem:
      provide the exception thrown during method invocation made by means
      of reflection mechanism.

      Another possible solution is to allow loading exceptions to pass through
      the invocation of Class.forName(). This is less preferable for following reasons:

      1. such specification change is not backward-compatible
      2. the Class.forName() become less convenient to use as it must be surrounded
         with more catch clauses
      3. if the set of loading and linking exceptions will ever change, this will cause
         the change of the Class.forName() specification


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              gbrachasunw Gilad Bracha (Inactive)
              Reporter:
              rfqsunw Rfq Rfq (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: