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

    • low
    • Deprecating a long-used method, additional warnings expected, etc.
    • Java API
    • 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

              darcy Joe Darcy
              darcy Joe Darcy
              Stuart Marks
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: