Bug 283225 - [1.6][compiler] classfile versus source conformance check too strict
Summary: [1.6][compiler] classfile versus source conformance check too strict
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-11 12:51 EDT by pohl CLA
Modified: 2009-08-05 02:23 EDT (History)
5 users (show)

See Also:


Attachments
Screenshot of the offending preference panel (63.44 KB, image/png)
2009-07-11 12:51 EDT, pohl CLA
no flags Details
simple test case (320 bytes, application/octet-stream)
2009-07-11 22:08 EDT, pohl CLA
no flags Details
Proposed fix (1.68 KB, patch)
2009-07-27 15:29 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pohl CLA 2009-07-11 12:51:01 EDT
Created attachment 141358 [details]
Screenshot of the offending preference panel

Build ID: 20090621-0832

Steps To Reproduce:
Context:   You have a project that uses @Override on interface implementation methods.  This was not allowed in Java 1.5, but is allowed in Java 1.6.   You also need to be able to load the resulting classfiles in a Java 1.5 VM.  

(Example:  You are using GWT, and the Java2Javascript compiler is limited to 1.5 classfiles because GWT Hosted Mode is limited to a 32-bit VM, because it uses an older version of SWT on MacOS X that uses the 32-bit Carbon libraries.)

1.  Preferences -> Java -> Compiler
2.  Set compiler compliance level to 1.6
3.  Uncheck "Use default compliance settings"
4.  Set "Generated .class files compatibility" to 1.5
5.  Note a red error message saying "Classfile compatibility must be greater or equal to source compatibility".

The validation that Eclipse is doing here was sensible and relevant when going  from Java 1.4 to Java 1.5, because the introduction of Generics in 1.5 required classfile changes that could not load in a Java 1.4 VM.

The transition from 1.5 to 1.6, however, need not be this strict.  To my knowledge, the only syntactic change in 1.6 was the allowance of @Override on methods that implement an interface.    There does not seem to be any corresponding classfile format change that goes along with this.

Therefore, in my opinion, this check is too strict.


More information:
Comment 1 Remy Suen CLA 2009-07-11 21:43:56 EDT
(In reply to comment #0)
> The transition from 1.5 to 1.6, however, need not be this strict.  To my
> knowledge, the only syntactic change in 1.6 was the allowance of @Override on
> methods that implement an interface.    There does not seem to be any
> corresponding classfile format change that goes along with this.

I believe there was still a 50.0 to 51.0 version number change. JDT/Core would know more.
Comment 2 pohl CLA 2009-07-11 22:08:46 EDT
Created attachment 141367 [details]
simple test case

I have attached a simple test case.   From the command line I can compile this code with "javac Test.java -target 1.5"  - using the compiler in the 1.6 JDK - and I can run the resulting class using the 1.5 runtime.   

If I attempt to compile using version 1.5 of javac, on the other hand, it gives the following error:

terminator-2:test pohl$ javac Test.java 
Test.java:8: method does not override a method from its superclass
	@Override
         ^
1 error


This proves, to me, that eclipse should be able to accomplish the same that I can do from the command line.  It is only the user interface that prevents me from building 1.6 source while targeting a 1.5 class file format.
Comment 3 Olivier Thomann CLA 2009-07-27 15:27:08 EDT
For the first comment,

you need to set the source level to be 1.5 as well. And then you don't get the configuration issue.
This is still not enough to fix this issue as we report:

----------
1. ERROR in D:\tests_sources\X.java (at line 9)
	public void hello() {
	            ^^^^^^^
The method hello() of type X.MyClass must override a superclass method
----------

I think we need to use the compliance version to report this error instead of the target platform or the source versions.
Comment 4 Olivier Thomann CLA 2009-07-27 15:29:30 EDT
Created attachment 142695 [details]
Proposed fix

All tests need to be run.
Comment 5 Olivier Thomann CLA 2009-07-27 15:32:32 EDT
Kent, please review.
It looks like we should use the compliance level instead of the source level to report for @Override being used for implementation of interface methods.
I need to run all tests to see if they need to be updated.

There is no plan to fix the configuration issue if the source level is not modified. Source cannot be higher than the target version.

javac has the same limitation:
javac -target 1.5 -source 1.6 X.java
fails with:
javac: source release 1.6 requires target release 1.6
Comment 6 Olivier Thomann CLA 2009-07-27 18:30:41 EDT
Released for 3.6M1.
Added regression test in:
org.eclipse.jdt.core.tests.compiler.regression.Compliance_1_6
Comment 7 Jay Arthanareeswaran CLA 2009-08-05 01:55:34 EDT
Verified for 3.6M1 using I20090803-1800