Community
Participate
Working Groups
Build ID: 3.2.1.M20060921-0945 Steps To Reproduce: The source code below is compiled differently by javac (1.5.0_08) and eclipse compiler. The eclipse compiler created two sequental checkcast instructions. Source code: package xyz; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; public class CheckCast { private void processLocks(HashMap locksMap, Object key) { for (Iterator iter = locksMap.keySet().iterator(); iter.hasNext();) { Object call = iter.next(); List locks = externLocks((Collection) locksMap.get(call), call); // ... } } private List externLocks(Collection locks, Object call) { List result = new ArrayList(); // .. return result; } } javac -p -private ... for class compiled with javac: ... private void processLocks(java.util.HashMap, java.lang.Object); Code: 0: aload_1 ... 29: aload 4 31: invokevirtual #6; //Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object; 34: checkcast #7; //class java/util/Collection 37: aload 4 ... javac -p -private ... for class compiled with the eclipse compiler: ... private void processLocks(java.util.HashMap, java.lang.Object); Code: 0: aload_1 ... 25: invokevirtual #34; //Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object; 28: checkcast #38; //class java/util/Collection 31: checkcast #38; //class java/util/Collection 34: aload 4 36: invokespecial #40; //Method externLocks:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List; ... More information: Default settings are used for project, compiler compliance level 5.0.
This is indeed suboptimal. I'll investigate. Too late for 3.2.2.
More information: the extra checkcast does not appear if compiler compliance level is set to 1.4.
There seems to be an irrelevant generic cast inserted.
We were protecting against such a situation, but not perfectly. The postConversionType is an erased type, which doesn't compare identical to a raw/param type.
Created attachment 59593 [details] Proposed patch
Fixed
Verified for 3.3 M6 using build I20070320-0010