Bug 186457 - Breaking inconsistency between java.nio.Charset in java and in Eclipse
Summary: Breaking inconsistency between java.nio.Charset in java and in Eclipse
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 RC2   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-10 16:44 EDT by Andrew Macheret CLA
Modified: 2007-05-28 09:00 EDT (History)
0 users

See Also:


Attachments
Demonstration of the bug (770 bytes, text/java)
2007-05-10 16:49 EDT, Andrew Macheret CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Macheret CLA 2007-05-10 16:44:33 EDT
If the region between the stars (in the code below) is uncommented, Eclipse will not present a warning or error, but compiling the class with javac.exe will produce an error (java 1.4 will complain that it cannot override final method compareTo, and java 1.5 will complain that two compareTo methods have the same erasure).

If the region between the stars is commented, Eclipse will give an error saying that compareTo must be defined, but javac.exe will give no warnings or errors.


The bottom line is that there seems to be no way to build any project in Eclipse that contains a subclass of Charset!!!


// Begin code for CharsetSub.java :
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;

public class CharsetSub extends Charset {
    public CharsetSub(String name, String[] aliases) { super(name, aliases); }
    public CharsetEncoder newEncoder() { return null;  }
    public CharsetDecoder newDecoder() { return null;  }
    public boolean contains(Charset x) { return false; }

    //****************************** (the region between the stars)
     public int compareTo(Object obj) {
        return compareTo((Charset) obj);
    }
    //******************************

    public static void main(String[] args) {
        new CharsetSub("test", new String[] { "test" });
        System.out.println("Compilation succeeded.");
    }
}
Comment 1 Andrew Macheret CLA 2007-05-10 16:49:07 EDT
Created attachment 66778 [details]
Demonstration of the bug

Compile the code as is with javac.exe, and marvel at the error.
Compile it with Eclipse with the region between the stars commented, and marvel at that error.
Comment 2 Olivier Thomann CLA 2007-05-11 17:16:51 EDT
I'll try to extract a small test case.
Comment 3 Olivier Thomann CLA 2007-05-14 09:59:21 EDT
In 3.3, you don't need the method:
     public int compareTo(Object obj) {
        return compareTo((Charset) obj);
    }
anymore. It works fine.
Comment 4 Maxime Daniel CLA 2007-05-21 08:02:14 EDT
I could not reproduce the behavior you describe.
Both I20070517-1700 (3.3 RC1) and M20070212-1330 (3.2.2) report an error when the offending block is not commented out, and compile OK when it is commented out.
This is the same behavior as javac (1.5 and 6).
Released MethodVerifyTest#141 and 142 for regression detection purposes.
Closing as WORKSFORME.
Comment 5 Frederic Fusier CLA 2007-05-25 06:49:18 EDT
The problem is with 1.4.2. Eclipse does not report any error when compliance is 1.4 although javac does:

D:\usr\OTI\tests\jdk1.4.2>compile CharsetSub.java
java version "1.4.2_15-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_15-ea-b01)
Java HotSpot(TM) Client VM (build 1.4.2_15-ea-b01, mixed mode)
CharsetSub.java:13: compareTo(java.lang.Object) in CharsetSub cannot override compareTo(java.lang.Object) in java.nio.charset.Charset; overridden method is final
     public int compareTo(Object obj) {
                ^
Comment 6 Frederic Fusier CLA 2007-05-25 07:02:54 EDT
Hmm... In fact Eclipse does report an error with compliance 1.4 when JRE System Library 1.4.2 is used but does not when JRE >= 1.5 is used...

However, there's still a problem here because javac still report the same error whatever the JRE specified on the classpath (I've tried with 1.5.0 and 1.6.0).

So, it seems that as soon as the source level is set to 1.4, the compiler needs to report an error in this case...

Andrew, as you get the error if you refer to the correct JRE in your project, do you agree to reduce the severity of this bug to 'normal'?
Comment 7 Frederic Fusier CLA 2007-05-25 07:21:44 EDT
The compiler already had this problem in 3.2.2...
Comment 8 Frederic Fusier CLA 2007-05-28 06:31:48 EDT
Reduce the severity as there's a way to build a project that contains a subclass of Charset (as you did not answer to my comment 6, I guess you agreed... )
Comment 9 Maxime Daniel CLA 2007-05-28 07:54:08 EDT
(In reply to comment #6)
...
> However, there's still a problem here because javac still report the same error
> whatever the JRE specified on the classpath (I've tried with 1.5.0 and 1.6.0).
> 
Have discussed the issue with Frédéric today. Our tests so far show that:
- javac 1.4 referencing the 1.5 rt.jar in its bootclasspath gets an expected
  lib mismatch error: 'bad class file: \opt\jdk1.5.0\jre\lib\rt.jar(java/nio/charset/Charset.class) class file has wrong version 49.0, should be 48.0';
- javac 1.4 referencing the 1.5 rt.jar in its classpath does refer to the 1.4
  rt.jar indeed, hence this matches Eclipse using compliance 1.4 and JRE 1.4,
  which duly reports an error;
- javac 1.5 with -source 1.4 referencing the 1.5 rt.jar gets a warning but no
  error; no error is expected because the T of Comparable#compareTo gets erased;
  the matching Eclipse configuration works as well.

Comment 5 does not reveal any true problem, I'll hence mark the bug as WORKFORME  again. Please feel free to reopen if I missed a broken test case.
Comment 10 Frederic Fusier CLA 2007-05-28 09:00:42 EDT
Verified for 3.3 RC2 using I20070525-1350 build