Community
Participate
Working Groups
Using v741, the following code doesn't fail with a ClassCastException if the unused local is optimized out. If -preserveAllLocals is set, then the code fails as expected. Test case: class A<T> { public T foo(Object o) { return (T) o; // should get unchecked warning } } public class X { public static void main(String[] args) { A<X> a = new A<X>(); X s = a.foo(new Object()); } } Actual output after compilation: ---------- 1. WARNING in D:\tests_sources\X.java (at line 3) return (T) o; // should get unchecked warning ^^^^^ Type safety: Unchecked cast from Object to T ---------- 2. WARNING in D:\tests_sources\X.java (at line 10) X s = a.foo(new Object()); ^ The local variable s is never read ---------- 2 problems (2 warnings) This is expected. At runtime, a class cast exception is expected. So the -preserveAllLocals option has a side-effect at runtime.
Other scenario broken as well: class A<T> { public T foo; } public class X { public static void main(String[] args) { A<X> a = new A<X>(); A ua = a; ua.foo = new Object(); try { X s = a.foo; } catch(ClassCastException e) { System.out.println("SUCCESS"); return; } System.out.println("FAILED"); } }
Other variation: class A<T> { public T foo; } public class X extends A<X>{ public static void main(String[] args) { new X().foo(); } public void foo() { A ua = this; ua.foo = new Object(); try { X s = foo; } catch(ClassCastException e) { System.out.println("SUCCESS"); return; } System.out.println("FAILED"); } }
More: class A<T> { public T foo; } public class X extends A<X>{ public static void main(String[] args) { new X().foo(); } public void foo() { A ua = this; ua.foo = new Object(); try { X s = this.foo; } catch(ClassCastException e) { System.out.println("SUCCESS"); return; } System.out.println("FAILED"); } }
Created attachment 60750 [details] In progress patch Olivier - pls check test1111 which seems to raise a stackmap issue (verifyError) (patch is still incomplete - need support for qname, allocation)
Created attachment 60757 [details] Proposed fix This patch is fixing the VerifyError issue in the SingleNameReference by adding a extra pop of the required value. This patch replaces the previous patch for the org.eclipse.jdt.core plugin. It doesn't contain the regression tests added in GenericTypeTests.
Added GenericTypeTest#test1111-test1117.
Created attachment 60920 [details] Proposed patch Includes fix for bug 177372
Created attachment 60927 [details] Better patch better tests
Released for 3.3M6 backporting to 3.2 maintenance
Created attachment 60990 [details] Proposed patch for 3.2.x
Verified for 3.3 M6 using build I20070320-0010