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

JDK 7 javac accepts "new <String>ArrayList()" with only warning

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 7
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • Introduced In Build:
      b03
    • Introduced In Version:
      7
    • CPU:
      x86
    • OS:
      linux

      Description

      The JDK 7 compiler seems to accept (with warning) a strange construction that earlier versions of the compiler reject (albeit with an odd error message).

      $ cat StrangeGenerics.java
      import java.util.ArrayList;
      import java.util.List;
      class StrangeGenerics {
          void m() {
              List<String> x = new <String>ArrayList();
          }
      }
      $ /space/jdk5/bin/javac -J-showversion -d /tmp -Xlint -source 1.5 StrangeGenerics.java
      java version "1.5.0_15"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
      Java HotSpot(TM) Server VM (build 1.5.0_15-b04, mixed mode)

      StrangeGenerics.java:5: cannot find symbol
      symbol : constructor <java.lang.String>ArrayList()
      location: class java.util.ArrayList
              List<String> x = new <String>ArrayList();
                               ^
      1 error
      $ /space/jdk6/bin/javac -J-showversion -d /tmp -Xlint -source 1.5 StrangeGenerics.java
      java version "1.6.0_11"
      Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
      Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

      StrangeGenerics.java:5: cannot find symbol
      symbol : constructor <java.lang.String>ArrayList()
      location: class java.util.ArrayList
              List<String> x = new <String>ArrayList();
                               ^
      1 error
      $ /space/jdk7/bin/javac -J-showversion -d /tmp -Xlint -source 1.5 StrangeGenerics.java
      java version "1.7.0-ea"
      Java(TM) SE Runtime Environment (build 1.7.0-ea-b43)
      Java HotSpot(TM) Client VM (build 14.0-b10, mixed mode, sharing)

      StrangeGenerics.java:5: warning: [rawtypes] found raw type: java.util.ArrayList
      missing type parameters for generic class java.util.ArrayList<E>
              List<String> x = new <String>ArrayList();
                                           ^
      StrangeGenerics.java:5: warning: [unchecked] unchecked conversion
      found : java.util.ArrayList
      required: java.util.List<java.lang.String>
              List<String> x = new <String>ArrayList();
                               ^
      2 warnings

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mcimadamore Maurizio Cimadamore
              Reporter:
              jglick Jesse Glick (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: