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

Inaccurate warning for a return value from an incomplete parameterized class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • tools
    • x86
    • windows_xp



      Name: jl125535 Date: 08/30/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b60)
      Java HotSpot(TM) Client VM (build 1.5.0-beta3-b60, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      Javac gets carried away by unused/irrelevant type parameters and starts giving false alarms on concretely-typed _inherited_ members.
      In this sample both Bug$A and Bug$B inherit from Vector<String>. So it's a compile-time FACT that the invocation of the method #elements() yields an enumeration of Strings in both cases. So the parameterisation of Bug$B should have no influence on the outcome of that operation.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the sample code provided with "-Xlint:unchecked" on.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All 3 assignments to Enumeration<String> are type sound so the javac mustn't emit any warnings.
      ACTUAL -
        Bug.java:8: warning: [unchecked] unchecked conversion
      found : java.util.Enumeration
      required: java.util.Enumeration<java.lang.String>
                      Enumeration<String> e2 = new B().elements(); // Unchecked conversion?!

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class Bug {

      public static void main(String[] args){
      Enumeration<String> e1 = new A().elements();

      Enumeration<String> e2 = new B().elements(); // Unchecked conversion?!
      Enumeration<String> e3 = new B<Thread>().elements();
      }

      static class A extends Vector<String> {}

      static class B <X> extends Vector<String> {}
      }
      ---------- END SOURCE ----------
      (Incident Review ID: 301336)
      ======================================================================

            ahe Peter Ahe
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: