Bug 124943 - [1.4][compiler] 1.4 Compiler Compliance not working for compareTo
Summary: [1.4][compiler] 1.4 Compiler Compliance not working for compareTo
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 153734 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-01-23 16:33 EST by bernardo CLA
Modified: 2006-09-06 11:32 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bernardo CLA 2006-01-23 16:33:31 EST
Using Ecliipse 3.1.1 on the Ubuntu BreezyBadger release on PC to compile a Java Project written for 1.4.  The compiler compliance level, generated .class files compatability, and source compatability are set to 1.4.  'Use default compliance settings' is also unchecked.

With these settings, the ((String)o).compareTo( o ) is not accepted.  With the same code compiled with the SUN javac tool using the -source option of 1.4:

javac -source 1.4 Prgm04.java

The compile works.  The JDT needs to accept the 1.4 option.

The test case used is as follows:

import java.io.*;
import java.util.*;
import java.lang.*;

public class Prgm04
{
	public static void main(String args[])
	{
	try{

		
		Object obj1 = new String("Hello");

		
		if( ((String)obj1).compareTo(obj1)==0)
		{
			System.out.println("There is a match");
		}
		else
		{
			System.out.println("There is no match");
		}
	}catch(Exception e) { }
	}
}
Comment 1 Olivier Thomann CLA 2006-01-23 19:10:43 EST
It compiles fine if a 1.4 library is used.
If a 1.5 library is used, an error is reported.

javac 1.5 with -source 1.4 compiles this code fine, but fails like we do in 1.5 mode.

So this is an issue with source level 1.4 with a 1.5 library used and compliance 1.5.

Kent, any idea how this can be fixed?
Comment 2 Kent Johnson CLA 2006-01-24 12:48:06 EST
"So this is an issue with source level 1.4 with a 1.5 library used and
compliance 1.5."

I cannot even create a project with those settings. I get an error saying 'Classfile compatibility must be equal or less than source compatibility'

How did you create it?
Comment 3 Kent Johnson CLA 2006-01-24 12:49:13 EST
Sorry - forget that.

Compliance != classfile compatibility
Comment 4 Philipe Mulet CLA 2006-01-27 12:03:46 EST
Proposal is to consider bridge methods if sourceLevel < 1.5.
Pls backport to 3.1.x stream as well.
Comment 5 Olivier Thomann CLA 2006-01-27 13:06:54 EST
When you say that it passes using javac, you are not comparing the same thing.
javac -source 1.4 .....

would correspond to:
- compliance 1.5
- source 1.4
-target 1.4
Comment 6 Kent Johnson CLA 2006-01-27 14:36:45 EST
Added GenericType test886

Released into HEAD, will appear in 3.2M5.

And as Olivier mentioned, this support is for compliance level 1.5 & source level 1.4. If you want compliance to be 1.4, then please use a 1.4.2 JRE.
Comment 7 Kent Johnson CLA 2006-01-27 14:51:29 EST
Backported to 3.1.3 stream.
Comment 8 David Audel CLA 2006-02-14 09:11:43 EST
Verified for 3.2 M5 using build I20060214-0010
Comment 9 Heath Borders CLA 2006-06-08 12:01:37 EDT
This is just a confirmation because I'm having a similar problem:

Does this mean that if I'm needing to compile for a 1.4 JRE, I need to be running eclipse in a 1.4 JRE?  I'm having the same problem running Sun's 1.5.0_07 JRE, Eclipse 3.1.2M2 with all compiler levels set to 1.4.  I would think it would be totally valid to run eclipse with the latest JRE, but run/compile against an older one.  Sorry if this is repetitive, but I want to know how much VM flexibility I have when running eclipse.

Thanks.
Comment 10 Heath Borders CLA 2006-06-08 12:38:49 EDT
(In reply to comment #9)
> ...I would
> think it would be totally valid to run eclipse with the latest JRE, but
> run/compile against an older one.

According to the javac 1.5.0 docs (http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javac.html):
The -bootclasspath and -extdirs should be specified when cross-compiling.  Effectively, Eclipse's compiler settings do not allow changes to these to anything other than the default.  That leads comment #6.

I'm guessing that you guys build eclipse for 1.3 compliance (I don't see 'assert's anywhere in your code), so does that mean you run in a 1.3 JRE?

Comment 11 Kent Johnson CLA 2006-06-08 14:00:57 EDT
No we do not run Eclipse on 1.3 VMs. Various people use 1.4 or 1.5 VMs.

"I would think it would be totally valid to run eclipse with the latest JRE, but run/compile against an older one."

Yes it is but the fix for this bug did not make it into 3.1.2 so until you upgrade to 3.2RC7, you'll have to run on a 1.4.x VM if you do not want to change compliance to 1.5.
Comment 12 Heath Borders CLA 2006-06-08 14:09:25 EDT
Thank you very much for your response.  One additional question:
In comment #10, I mentioned the javac docs that say you should specify a bootclasspath and extdirs when compiling.  How does the eclipse compiler get around this requirement?
Comment 13 Kent Johnson CLA 2006-06-08 14:52:26 EDT
We have our own compiler. We do not run javac.
Comment 14 Heath Borders CLA 2006-06-08 14:57:37 EDT
Yes, I understand that.  But, I'm guessing that javac allows you to specify the bootclasspath so that there is no chance of hooking into an API that isn't compatible with your target JRE.  I'm wondering how your compiler gets around the need for a different bootclasspath at compile time.  If this isn't an appropriate question for this bug, could you point me in the direction of the appropriate resources?

Thanks.
Comment 15 Gernot CLA 2006-08-14 10:49:10 EDT
*** Bug 153734 has been marked as a duplicate of this bug. ***