Community
Participate
Working Groups
Created attachment 235123 [details] SneakyCaster.java To reproduce, compile (and then run) the attached SneakyCaster.java using both javac and ECJ. ECJ misses the checkcast instruction at the end of the cast() method. This allows assignment of an Object to a Runnable variable. Eventually, the JVM throws an IncompatibleClassChangeError, but clearly, as there is only one .class file, that's not right. javac correctly includes the checkcast instruction, and a ClassCastException is thrown before the invalid assignment could ever be made.
Stephan, thanks for taking a look! BTW, I can reproduce this in 4.3.1 as well as 4.3.
Bug already exists since generics got introduced to ecj. It seems I got more urgent things on my plate, but I'll keep it on my radar.
(In reply to Stephan Herrmann from comment #2) > Bug already exists since generics got introduced to ecj. Thanks for that information. We will take a look at this for 4.5 after the Java 8 maintenance work's urgent issues are addressed.
I agree the error message is somewhat confusing. Code generated by javac includes a cast in cast() method - which produces a CCE when run, but the cast in cast() is really not justified.
(In reply to Srikanth Sankaran from comment #4) > I agree the error message is somewhat confusing. Code generated by javac > includes a cast in cast() method - which produces a CCE when run, but the > cast in cast() is really not justified. I need to take a closer look - the workspace had a bunch of unrelated changes while I was debugging this scenario. I will look into this for 4.5 M2.
Amzzingly, org.eclipse.jdt.internal.compiler.ast.SingleNameReference.computeConversion(Scope, TypeBinding, TypeBinding) is lacking any treatment of locals. Only fields are handled there. I think the genericCast attribute would need to get updated there to produce a checkcast in cast()
Fix and tests released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=6fe04df602475d9f13e955fcfd38124da359e84a
Verified for 4.5 M2 using build I20140916-2000
+1 for back porting, reopening.
Released in R4_4_maintenance via commit(s): http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R4_4_maintenance&id=3c5d92e016f995dd43c0cbda18d4e4cb505ad3d4
Verified for 4.4.2 RC1 using build M20150114-1500.