Summary: | 1.5 compiler does not understand class files built by -target jsr14 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | John Mazzitelli <mazz> | ||||||||||
Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||||||||
Status: | VERIFIED FIXED | QA Contact: | |||||||||||
Severity: | normal | ||||||||||||
Priority: | P3 | CC: | philippe_mulet | ||||||||||
Version: | 3.2.2 | Flags: | philippe_mulet:
review+
|
||||||||||
Target Milestone: | 3.3 RC1 | ||||||||||||
Hardware: | PC | ||||||||||||
OS: | Windows XP | ||||||||||||
Whiteboard: | |||||||||||||
Attachments: |
|
Description
John Mazzitelli
2007-05-09 11:27:42 EDT
Created attachment 66492 [details]
project that replicates the bug
See "steps to reproduce" in bug description to know what to do with the attached .zip file in order to replicate the bug.
Passing over to JDT This is because javac knows how to read the attribute called Varargs and we don't. When you compile your class with target jsr14, instead of setting a bit to ACC_VARARGS(0x0080) javac decides to add a new (unspecified) attribute called Varargs to tag the method as a vararg method. Then when javac reads back the .class file that contains this method, it can recognize that this is a varargs method. The Eclipse compiler doesn't recognize the varargs attribute and therefore doesn't know what it means. The method is not tagged as a vararg method and the code doesn't compile. The worksaround is to wrap your parameter in an array. Note that javac 1.4.2 also reports the same issue: X.java:4: varargMethod(java.lang.Object[]) in VarargClass cannot be applied to (java.lang.String) String results = VarargClass.varargMethod(arg); ^ 1 error So your code won't compile anyway with a 1.4 compiler. If you set javac 1.5 to compile in 1.4 mode, you also cannot compile the code: d:\tests_sources>javac X.java -classpath java4.jar -target 1.4 -source 1.4 X.java:4: varargMethod(java.lang.Object[]) in VarargClass cannot be applied to (java.lang.String) String results = VarargClass.varargMethod(arg); ^ 1 error d:\tests_sources>javac X.java -classpath java4.jar -target jsr14 -source 1.4 X.java:4: varargMethod(java.lang.Object[]) in VarargClass cannot be applied to (java.lang.String) String results = VarargClass.varargMethod(arg); ^ 1 error So from my point of view, there is no point of compiling using jsr14, if you then need to compile with target and source to 1.5 in order to be able to use the varargs methods as a varargs method. Why not compiling everything in target 1.5 and then you would not have a problem reported by the Eclipse compiler? If you wrap your parameter inside an array of String, the code compiles fine and in this case you would not need this special attribute. Philippe, do you think we should handle this case? Created attachment 66747 [details]
Proposed fix
The fix is absolutely trivial.
nice - can I assume that when you say, "the fix is absolutely trivial" that it is equally trivial to put the fix in the next Eclipse release? :-) This is getting late in the game. Philippe, do you believe we should fix this one? It might improve our support for users that are mixed between 1.4 and 1.5. The fix is a no risk fix. We don't generate the attribute when the Eclipse batch compiler is used with target 1.4. And this doesn't prevent the resulting .class file from being run on a 1.4 VM. I could emulate the same attribute, but I don't feel this is necessary. We might just want to keep the support to read it. I think if we support reading the attribute, we should also support writing it (in -target jsr14 mode only); so we can consume our output. Is this behavior spec'ed anywhere, or is this a javac hack we would try to mimic ? Re: comment 8 "(in -target jsr14 mode only)" I think this simply means technically if target is 1.4 as you said earlier Olivier. I'll prepare a patch for 3.3RC1 that will also include the generation of this attribute. Created attachment 66881 [details]
New patch
This new patch:
- read the Varargs attribute from existing .class file (compiled with Eclipse compiler or javac using target jsr14)
- generate the Varargs attribute if the code is compiled with target jsr14. This is done by clearing the bit from the access flags of the method info and adding an attribute.
- update the disassembler to also recognize the new attribute.
Philippe, please review. Created attachment 66898 [details]
Regression test
Released for 3.3RC1. thanks for the quick turnaround No problem. When the fix is that simple and has no impact on "normal" use case and provide a good value, then it is ok to fix it now. I encourage you to try the next integration build or 3.3RC1 build and confirm that this is fixed. Thank you. Regression test is: org.eclipse.jdt.core.tests.compiler.regression.VarargsTest#test060 Verified for 3.3 RC1 using I20070515-0010 |