JDK-6846972 : cannot access member of raw type when erasure change overriding into overloading
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic,unknown
  • Submitted: 2009-06-01
  • Updated: 2012-03-22
  • Resolved: 2012-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b68Fixed
Related Reports
Duplicate :  
Relates :  
Description
Please see the following mini test (JCK tests use the similar code pattern):
---------------------------------------------------------
import java.util.EnumMap;

enum Suit {
    CLUBS, DIAMONDS;
}

public class minitest {
    static Object [] array = {
        Suit.CLUBS, "value1",
        Suit.DIAMONDS, "value2"
    };

    public static void main(String[] args) {
        EnumMap map = new EnumMap(Suit.class);
        map.put(array[0], array[1]);
    }
}
---------------------------------------------------------

It compiles on JDK b54, and fails on b55 with the output:
---------------------------------------------------------
minitest.java:15: cannot find symbol
        map.put(array[0], array[1]);
           ^
  symbol:   method put(java.lang.Object,java.lang.Object)
  location: class java.util.EnumMap
---------------------------------------------------------

Could you please clarify is this behavior correct ?

Comments
SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk7/tl/langtools/rev/ad07b7ea9685
15-07-2009

EVALUATION The JLS concludes that Map.put(Object,Object) and EnumMap.put(Enum,Object) both exist in EnumMap. Pre-generics, the client expected EnumMap.put(Object,Object) to override Map.put(Object, Object). Map and EnumMap could have been generified independently of the client, with the intent that EnumMap.put(K,V) overrides Map.put(K,V). However, when the legacy client is recompiled, it would believe that EnumMap.put(Enum,Object) overloads Map.put(Object,Object). To say the legacy client has an error is wrong because there is nothing it can do except stop its use of raw EnumMap. That's tantamount to dropping migration compatibility. The answer is for javac to give a warning rather than an error at the call to EnumMap.put(Object,Object). The JLS does not currently require that ANY invocation on an object of raw type must give a warning, but it should. To accurately compute when a warning is really justified is very tricky, requiring analysis of the erased and non-erased signatures of all methods with the same name. (This seems akin to detecting when bridge methods are required, though.) Alex
01-06-2009