Bug 210866 - Compilation error when extending java.io.PrintWriter
Summary: Compilation error when extending java.io.PrintWriter
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-25 14:42 EST by Daniel Bonniot CLA
Modified: 2009-02-14 12:12 EST (History)
6 users (show)

See Also:


Attachments
Source code (139 bytes, text/x-java)
2007-11-25 14:42 EST, Daniel Bonniot CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bonniot CLA 2007-11-25 14:42:00 EST
Created attachment 83723 [details]
Source code

Build ID: v_774_R33x, 3.3.1

Steps To Reproduce:
daniel /tmp/bug cat OutPort.java
abstract class OutPort extends java.io.PrintWriter {
  OutPort(java.io.Writer base, boolean autoflush) {
    super(base, autoflush);
  }
}

daniel /tmp/bug javac OutPort.java

daniel /tmp/bug ecj OutPort.java
----------
1. ERROR in OutPort.java (at line 1)
        abstract class OutPort extends java.io.PrintWriter {
                       ^^^^^^^
Exception IOException in throws clause of Writer.append(CharSequence, int, int) is not compatible with PrintWriter.append(CharSequence, int, int)
----------
2. ERROR in OutPort.java (at line 1)
        abstract class OutPort extends java.io.PrintWriter {
                       ^^^^^^^
Exception IOException in throws clause of Writer.append(CharSequence) is not compatible with PrintWriter.append(CharSequence)
----------
3. ERROR in OutPort.java (at line 1)
        abstract class OutPort extends java.io.PrintWriter {
                       ^^^^^^^
Exception IOException in throws clause of Writer.append(char) is not compatible with PrintWriter.append(char)
----------
3 problems (3 errors)%

daniel /tmp/bug ecj -version
Eclipse Java Compiler v_774_R33x, 3.3.1, Copyright IBM Corp 2000, 2007. All rights reserved.


More information:
Comment 1 Frederic Fusier CLA 2007-11-26 03:25:40 EST
These errors only happen while compiling the source with compliance 1.4 against a JRE 1.5 System library. But it's true that javac does not complain with the same configuration...

This still occurs in 3.4.
Comment 2 Philipe Mulet CLA 2007-11-26 06:44:54 EST
Smells like bug 209429
Comment 3 Andrew Overholt CLA 2008-03-06 16:23:02 EST
I'm having difficulty building the Eclipse SDK with a 1.6 JVM.
Comment 4 Kent Johnson CLA 2008-03-27 15:42:29 EDT
seems the same as bug 79798 
Comment 5 Kent Johnson CLA 2008-04-23 15:53:20 EDT
Actually this is not a bug. Its a configuration problem.

If you're going to compile against 1.5 class libraries then your compliance must be set to 1.5.

You may set your source level to 1.4 or lower if you want but the compliance level cannot be below the level of your class libaries.

To duplicate with javac, use javac 1.4 but change the bootclasspath to point at the 1.5 class libraries - your example will fail in the same way.
Comment 6 David Audel CLA 2008-04-28 11:35:03 EDT
Verified for 3.4M7 using I20080427-2000
Comment 7 Stephane E. Potvin CLA 2009-02-14 08:09:42 EST
Would it be possible to reopen this?

Kent, you can't expect javac 1.4 to work with 1.5 class libraries as javac 1.4 is not forward compatible with 1.5. javac 1.5, on the other hand, is backward compatible and works as expected when asked to generate classes with 1.4 (or lower) source and binary compatibility.

This issue is making the eclipse source build fail in org.eclipse.pde.build unless you have actual 1.4 boot classes installed. I do know that it's not a supported combination (not having real 1.4 boot classes) but on some platforms (like FreeBSD in my case), jdk1.4 is just not available.

If I use the real javac instead of jdt, I can successfully build org.eclipse.pde.build with a target compliance level of 1.2. I would expect the JDT to handle this the same way as javac does.

% java -jar jarcheck.jar pdebuild.jar 1.1 1.4
Checking jar ./pdebuild.jar
[...]
   OK 1.2 (46) org/eclipse/pde/internal/build/FeatureWriter.class
[...]

This is an excerpt from a small utility that check the compliance level java class files. The FeatureWriter class is a extending PrintWriter. The pdebuild.jar was built using javac instead of JDT.
Comment 8 Philipe Mulet CLA 2009-02-14 12:12:20 EST
If you want to mimic javac behavior here, simply provide the 1.4 Java class libraries explicitly on the build path (or bootclasspath). Javac does inject these implicitly, ECJ doesn't.