Bug 473748 - ClassCastException when using types parameterized with primitive arrays and varargs
Summary: ClassCastException when using types parameterized with primitive arrays and v...
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.8.5   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-28 08:39 EDT by Krzysztof Szafranski CLA
Modified: 2015-08-05 15:53 EDT (History)
1 user (show)

See Also:


Attachments
Examples reproducing the issue (343 bytes, application/octet-stream)
2015-07-28 08:39 EDT, Krzysztof Szafranski CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Szafranski CLA 2015-07-28 08:39:03 EDT
Created attachment 255478 [details]
Examples reproducing the issue

This issue appears when we are passing a result of a type-parameterized method directly to a varargs method. The behavior is different when compiling with javac and with ajc.

When I compile and run the attached file with javac (1.8.0_40) everything works fine. But when I compile it with ajc:
java -jar /path/to/aspectjtools-1.8.5.jar GenericVarargsBug.java -1.8

I'm getting ClassCastException:
Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
	at GenericVarargsBug.main(GenericVarargsBug.java:9)

It seems that while javac treats the byte array as a single Object argument to the varargs method, ajc tries to cast it to Object array.

The issue does not appear when the result of sth.get(0) is saved to an intermediary variable, e.g.:
byte[] first = sth.get(0);
isItWorking(first);

I'm also attaching two more examples of how to reproduce this issue.
Comment 1 Andrew Clement CLA 2015-08-05 15:53:30 EDT
I just tried your snippet in pure Eclipse and it seems to be a bug there (The AspectJ compiler piece is based on the eclipse compiler). I've raised bug 474355 to track it in  JDT. Possibly it is already fixed in JDT master but I haven't checked that, I only checked the mars (4.5.0) release.

Once there is a fix and we know where it is I will pick it up when I fold the new compiler version from eclipse into AspectJ. Thanks for the small code snippet, they are so useful.