Community
Participate
Working Groups
When compiling the following class: public class Main { public static void main (String [] args) { StringBuffer s1 = new StringBuffer (); s1.append (new StringBuffer ()); } } // end of class Eclipse 2.1 GA will emit code that uses Java 1.4-only StringBuffer.append (StringBuffer) method regardless of JDK or .class compliance level settings [the following javap dump was obtained when using JDK 1.3 compatibility with default compliance settings]: Compiled from Main.java public class Main extends java.lang.Object { public Main(); public static void main(java.lang.String[]); } Method Main() 0 aload_0 1 invokespecial #9 <Method java.lang.Object()> 4 return Method void main(java.lang.String[]) 0 new #17 <Class java.lang.StringBuffer> 3 dup 4 invokespecial #18 <Method java.lang.StringBuffer()> 7 astore_1 8 aload_1 9 new #17 <Class java.lang.StringBuffer> 12 dup 13 invokespecial #18 <Method java.lang.StringBuffer()> 16 invokevirtual #22 <Method java.lang.StringBuffer append (java.lang.StringBuffer)> 19 pop 20 return Note that even though the major/minor version of the emitted .class file is 45/3 (i.e., JVM 1.1-compliant), the class can only run in JVM 1.4 and up despite the fact that the source is Java 1.1-compatible. The correct behavior for emitting JDK 1.3-compatible code would be to use StringBuffer.append(Object) method.
You are compiling your code against the JDK 1.4 libraries. This is why the 1.4 method is used. If you compile the same code against 1.3 libraries, the append (Object) method is used. The compiler uses the method available in the libraries you use to compile. If you don't want 1.4 API to be used, why do you compile against them? You can compile against 1.3 libraries and run against 1.4 without any problem. You simply need to install more than one JRE in your workspace and select the one you want for the runtime. So I don't see any bug. The compliance level is used to set the way the compiler should perform nameloopuk,... Some of them change between 1.3 and 1.4, but this compliance level has no impact on the API used in the compiled code.
Eclipse generates no warnings about 1.4 libraries being used when Java 1.3 compliance is requested. In the above case most users will not know that they are in fact not generating 1.3-compatible code.
The problem is that there is no way to distinguish a 1.3 libraries from 1.4 libraries. It is up to the user to know what libraries he/she is compiling against. This has nothing to do with the compliance setting.
We can detect such a case. This could definitely be improved. We might simply specify what is the compliance level.
Isn't the target JDK meant to deal with these ?
Javac will complain if trying to use 1.4 libraries for a 1.3 level compiler, arguing about wrong major/minor versions for the libraries. We should allow to compile, but still issue some notification under the same circumstances.
We should detect the case where 1.4 libraries are used in 1.3 compliant mode, and issue a classpath problem marker.
Added optional problem to diagnose this issue: Added JavaCore optional problem to detect incompatible required binaries, so as to flag situations where some prerequisite binaries are required a JRE level higher than the project target platform; i.e. compiling against 1.4 libraries when deploying for 1.1 platform is likely unwanted. * JAVACORE / Reporting Incompatible JDK Level for Required Binaries * Indicate the severity of the problem reported when a project prerequisites another project * or library with an incompatible target JDK level (e.g. project targeting 1.1 vm, but compiled against 1.4 libraries). * - option id: "org.eclipse.jdt.core.incompatibleJDKLevel" * - possible values: { "error", "warning", "ignore" } * - default: "ignore" It will likely be located amongst compiler preferences, under buildpath tab, and will default to 'ignore' for now.
Verified.
*** Bug 24412 has been marked as a duplicate of this bug. ***