Uploaded image for project: 'CCC Migration Project'
  1. CCC Migration Project
  2. CCC-6850612

Deprecate Class.newInstance since it violates the checked exception language contract

    XMLWordPrintable

    Details

    • Subcomponent:
    • Compatibility Risk:
      low
    • Compatibility Risk Description:
      Deprecating a long-used method, additional warnings expected, etc.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Deprecate Class.newInstance since it violates the general checked exception contract.

      Problem

      The Class.newInstance method knowingly violates the checked exception language checking and has done so for years.

      As part of the general deprecation review taking place in JDK 9, this method should also be deprecated.

      Solution

      Deprecate the method.

      Specification

      --- a/src/java.base/share/classes/java/lang/Class.java    Fri Apr 15 10:14:57 2016 -0700
      +++ b/src/java.base/share/classes/java/lang/Class.java    Mon Apr 18 18:00:41 2016 -0700
      @@ -470,7 +470,7 @@
            * expression with an empty argument list.  The class is initialized if it
            * has not already been initialized.
            *
      -     * <p>Note that this method propagates any exception thrown by the
      +     * @deprecated This method propagates any exception thrown by the
            * nullary constructor, including a checked exception.  Use of
            * this method effectively bypasses the compile-time exception
            * checking that would otherwise be performed by the compiler.
      @@ -500,6 +500,7 @@
            *          of this class.
            */
           @CallerSensitive
      +    @Deprecated(since="9")
           public T newInstance()
               throws InstantiationException, IllegalAccessException

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              darcy Joe Darcy
              Reviewed By:
              Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: