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

Spurious unchecked warning reported by javac

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 8
    • tools
    • b108
    • generic
    • generic
    • Verified

      java.lang.Integer and the other wrapper classes contain code like

          @SuppressWarnings("unchecked")
          public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");

      where Class.getPrimitiveClass is a package-private static method returning a Class<?>.

      Despite the @SuppressWarnings annotation, javac still reports an unchecked warning on this code:

      src/share/classes/java/lang/Integer.java:72: warning: [unchecked] unchecked cast
          public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
                                                                                             ^
        required: Class<Integer>
        found: Class<CAP#1>
        where CAP#1 is a fresh type-variable:
          CAP#1 extends Object from capture of ?

      This behavior is unfortunate since it frustrates efforts to resolve lint warnings in the JDK.

            jlahoda Jan Lahoda
            darcy Joe Darcy
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: