Bug 81535 - [compiler] compliance 1.5 should work with source 1.4 on 1.5 libraries
Summary: [compiler] compliance 1.5 should work with source 1.4 on 1.5 libraries
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-17 11:55 EST by Olivier Thomann CLA
Modified: 2006-02-20 04:33 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2004-12-17 11:55:37 EST
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class Test extends PrintWriter implements Runnable {
   public Test(OutputStreamWriter out, boolean flag) {
       super(out, flag);
   }
   public void run() {
   }
}

We report:
----------
1. ERROR in C:\tests_sources\Test.java
 (at line 3)
	public class Test extends PrintWriter implements Runnable {
	             ^^^^
The return type is incompatible with Writer.append(char), PrintWriter.append(char)
----------
2. ERROR in C:\tests_sources\Test.java
 (at line 3)
	public class Test extends PrintWriter implements Runnable {
	             ^^^^
The return type is incompatible with Writer.append(CharSequence, int, int),
PrintWriter.append(CharSequence, int, int)
----------
3. ERROR in C:\tests_sources\Test.java
 (at line 3)
	public class Test extends PrintWriter implements Runnable {
	             ^^^^
The return type is incompatible with Writer.append(CharSequence),
PrintWriter.append(CharSequence)
----------
3 problems (3 errors)

I believe this should work. If the source level is set to 1.5, it works.
Comment 1 Olivier Thomann CLA 2004-12-17 12:01:52 EST
javac 1.5 with -source 1.4 compiles this code.
Comment 2 Olivier Thomann CLA 2004-12-17 12:03:13 EST
Generic signatures would be ignored, I guess.
Comment 3 Kent Johnson CLA 2004-12-17 12:28:16 EST
Philippe: What does it mean to use -source 1.4 but -compliance 1.5?

Are 1.5 features supported or not? Are they supported in binaries or not?

Why do we have 2 flags?
Comment 4 Kent Johnson CLA 2005-01-06 16:03:58 EST
ping.
Comment 5 Olivier Thomann CLA 2005-01-06 16:17:11 EST
My understanding of the compliance 1.5 is that it means that it behaves like
javac 1.5 (for method lookup, covariance, ...).
The source level is used to find out what constructs are allowed. -source 1.5
means the autoboxing, enums, foreach, static import and generics are supported.
In the test case, you can see that there is no 1.5 constructs.
Comment 6 Philipe Mulet CLA 2005-01-06 19:32:00 EST
The compliance flag is to emulate a certain JDK level.
Now when you use JDK 1.4 compiler, you can also instruct it to compile in
-source 1.3. Same for 1.5, get a hold onto JDK 1.5, and compile with -source 1.4
mode.

Feels like a case where we trigger 1.5 behavior based on compliance level
instead of using the source level. Compliance level is determining behavior
common to all source levels (so compliance is master mode, then source level is
submode).
Comment 7 Kent Johnson CLA 2005-01-07 12:16:28 EST
Added MethodVerify test030
Comment 8 Andrew Gaydenko CLA 2005-01-09 17:54:15 EST
What changes are needed to be done for M4 source/build distribution for
successfull build?

Thanks!
Andrew (the issue was inspired by me :-)
Comment 9 Olivier Thomann CLA 2005-01-09 18:20:39 EST
I would need to replace the org.eclipse.jdt.core plugin with the one from a
nightly build that contains the fix.
http://download.eclipse.org/downloads/drops/N20050109-0010/index.php should be fine.
You just need to download the JDT Runtime Binary distribution and extract the
org.eclipse.jdt.core plugin from it and override the one from M4.
Comment 10 Andrew Gaydenko CLA 2005-01-09 18:52:46 EST
After replacing JDT-binary (and stripping "_3.1.0" in directry names )
I have got the same three errors. Must I modify something in build.xml files?
Comment 11 Philipe Mulet CLA 2005-01-10 06:17:13 EST
Covariance refers to the ability to narrow the return type of a method when
overriding it:

public class X {
  public Object foo() { return new X(); }
}
public class Y extends X {
  public Y foo() { return new Y(); }
}

Then when compiling:

class Z {
   {   new Y().foo();   }
}

The invocation of Y.foo() is targeting:  "#foo()Y"  (and not "#foo()Object").
However, a 1.4 compiler is not expecting such subtleties, hence the problems you
are seeing. By toggling the compiler compliance to 1.5 (keeping source level to
1.4 and target to 1.4) you would compile your code clear. But do not intend to
run it on a 1.4 VM in the end. The generated binaries are tagged as working on
1.4; but there are direct references to 1.5 specific constructs which have no
equivalent in true 1.4 libraries (for instance, there would be not "#foo()Y"
method in a real 1.4 library).
Comment 12 Andrew Gaydenko CLA 2005-01-10 08:06:26 EST
There are "-target" and "-source" javac options (and there are appropriate
properties in build.xml files, and I have tried to set them to "1.4" in all
the src/buid tree with the same result). But I have not found anything concerning
"-compliance" javac/ant property.
Comment 13 David Audel CLA 2005-02-16 05:42:49 EST
Verified in I20050215-2300
Comment 14 Philipe Mulet CLA 2006-02-20 04:33:04 EST
Note: testcase in comment 11 is invalid in -source 1.4 mode (even 1.5 compliance). The original bug was rather related to ignoring bridge methods in 1.5 libraries.
Comment 15 Philipe Mulet CLA 2006-02-20 04:33:12 EST
Note: testcase in comment 11 is invalid in -source 1.4 mode (even 1.5 compliance). The original bug was rather related to ignoring bridge methods in 1.5 libraries.

Also see bug 128560