Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 416480 - Error in bytecode generated by ECJ compiler leads to IncompatibleClassChangeError
Summary: Error in bytecode generated by ECJ compiler leads to IncompatibleClassChangeE...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.4.2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-03 18:00 EDT by Graham Stanton CLA
Modified: 2015-01-20 07:04 EST (History)
3 users (show)

See Also:


Attachments
SneakyCaster.java (432 bytes, text/plain)
2013-09-03 18:00 EDT, Graham Stanton CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Stanton CLA 2013-09-03 18:00:01 EDT
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.
Comment 1 Jay Arthanareeswaran CLA 2013-09-18 00:32:55 EDT
Stephan, thanks for taking a look!

BTW, I can reproduce this in 4.3.1 as well as 4.3.
Comment 2 Stephan Herrmann CLA 2013-09-19 18:52:54 EDT
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.
Comment 3 Srikanth Sankaran CLA 2014-04-14 03:26:33 EDT
(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.
Comment 4 Srikanth Sankaran CLA 2014-09-08 05:35:25 EDT
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.
Comment 5 Srikanth Sankaran CLA 2014-09-08 05:56:24 EDT
(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.
Comment 6 Srikanth Sankaran CLA 2014-09-08 06:10:59 EDT
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()
Comment 7 Srikanth Sankaran CLA 2014-09-08 08:56:04 EDT
Fix and tests released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=6fe04df602475d9f13e955fcfd38124da359e84a
Comment 8 Jay Arthanareeswaran CLA 2014-09-17 02:52:15 EDT
Verified for 4.5 M2 using build I20140916-2000
Comment 9 Jay Arthanareeswaran CLA 2014-10-30 02:06:10 EDT
+1 for back porting, reopening.
Comment 10 Jay Arthanareeswaran CLA 2014-11-06 03:54:54 EST
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
Comment 11 shankha banerjee CLA 2015-01-20 07:04:04 EST
Verified for 4.4.2 RC1 using build M20150114-1500.