Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 186438

Summary: Compiler compliance level has no effect
Product: [Eclipse Project] JDT Reporter: Andrew Mak <makandre>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 3.3   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Andrew Mak CLA 2007-05-10 15:02:59 EDT
I'm running eclipse 3.3M7 with a 1.5 level jdk.  In my workspace, I create a Java project (leaving the JRE at the default 1.5 level).  Then I change the project specific properties and set the compiler compliance level to 1.4.

I create the following class:

package test;
public class MyClass {	
	public static void main(String[] args) {
		System.out.println(MyClass.class.getSimpleName());
	}
}

Note that Class.getSimpleName() is a 1.5 method, so I expected to get some warning or error about it but I didn't get any.  And when I run this app using java 1.4 I will get an error:

Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Class: method getSimpleName()Ljava/lang/String; not found
	at test.MyClass.main(MyClass.java:6)
Comment 1 Olivier Thomann CLA 2007-05-10 15:06:15 EDT
The compiler is using the libraries on the classpath to know what methods are available. There is no clue that the getSimpleName() method exists only since 1.5.
If you want to run on a 1.4 VM, you better put a 1.4 library on your classpath.
The compliance has nothing to do with checking the methods used in the code.
Ok to close?
Comment 2 Andrew Mak CLA 2007-05-10 15:09:51 EDT
So what exactly does the compliance level setting give me?
Comment 3 Olivier Thomann CLA 2007-05-10 15:16:42 EDT
The compliance level means that it behaves like the javac of the same level.
So compliance 1.5 means javac 1.5, compliance 1.4 javac 1.4, ...
So the compliance will set the values for the source and target platform levels.
It doesn't change or check the libraries on the classpath.
If you do the same steps with javac, you get the same error.
from javac 1.5,
javac test\MyClass -target 1.4 -source 1.4
and then from a 1.4 VM:
java test.MyClass
This will report the same error.
Comment 4 Andrew Mak CLA 2007-05-10 15:26:07 EDT
Thanks for clarifying the use of that setting.  Yes, OK to close.
Comment 5 Jerome Lanneluc CLA 2007-05-11 04:13:32 EDT
Working as designed. Closing.
Comment 6 Andrew Mak CLA 2007-05-11 10:30:57 EDT
Closing.