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

Bug 539222

Summary: "--release" option is unavailable in project compiler settings
Product: [Eclipse Project] JDT Reporter: Stefan Moebius <stmoebius>
Component: UIAssignee: Kalyan Prasad Tatavarthi <kalyan_prasad>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: loskutov, simeon.danailov.andreev, stephan.herrmann
Version: 4.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Stefan Moebius CLA 2018-09-19 04:57:43 EDT
I'm using Photon on OpenJDK 10.0.2.
I have a project that is configured with these jdt prefs:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

However, the option to "Use '--release' option" on the project configuration UI is greyed out and not available. As per the documentation, it should be available "if the JRE being used is 9 or above and the compiler compliance is 1.6 or above."
Comment 1 Noopur Gupta CLA 2018-09-19 06:32:39 EDT
Kalyan, can you please have a look?
Comment 2 Kalyan Prasad Tatavarthi CLA 2018-09-19 07:05:20 EDT
@Stefan Moebius

Please provide screen shots of your Project compliance preference page.
Also please provide the screen shots of thee workspace preference page for 
Installed JREs and for Execution Environment when JavaSE-1.8 is selected on the page.
Comment 3 Kalyan Prasad Tatavarthi CLA 2018-10-24 07:04:35 EDT
I have not been able to reproduce this issue. Please reopen this bug if you are facing this issue even now.

Please provide screen shots of your Project compliance preference page.
Also please provide the screen shots of thee workspace preference page for 
Installed JREs and for Execution Environment when JavaSE-1.8 is selected on the page.
Comment 4 Simeon Andreev CLA 2020-02-06 04:03:38 EST
Hi Stephan,

I have a question regarding the "javac --release" option in the JDT compiler. We are planning to support Java 8 and Java 11 simultaneously in our product and I think we are running into some corner cases.

I see the following relevant bugs:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=527260 (support "--release N" in JDT)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=539222 (this ticket, "--release" checkbox disabled in Java project preference page)

In particular, our compiler (JDT+xtext) ran into a problem with a project that has JRE 8 on the classpath, but only JRE 11 installed in the workspace. In that case, I see that "--release 8" ("release=enabled") is not used, although "compliance=1.8" is used (in this bug I read that its expected, "release" is allowed only with JRE 9+).

What is the expected JDT behavior here? The project has JRE 8 on the classpath, so theoretically it doesn't need "--release 8". But JDT only has JRE 11 to compile against, which implies "--release 8" is needed.

I'm asking for JDT itself; we normally have both JREs available, a problem in our code causes JRE 8 to be missing in our compiler application (we'll try to fix our code to address the problem).


The stripped-down snippet is:

package test;
public class TestMath {
	public static void main(String[] args) {
		long a = 4L;
		long f = Math.floorDiv(a, 4);
		System.out.println(f);
	}
}

Exception in thread "main" java.lang.NoSuchMethodError: java.lang.Math.floorDiv(JI)J
	at test.TestMath.main(TestMath.java:7)

JRE 8 is on the classpath, compliance is set to 1.8, JRE 11 is the only installed JRE. The problem itself is expected, when "--release 8" is not used during the compile.

Best regards and thanks,
Simeon
Comment 5 Stephan Herrmann CLA 2020-02-06 09:43:42 EST
(In reply to Simeon Andreev from comment #4)

Some (probably incomplete) observations:


JDT/UI disables that check box for reasons that are obscure to me:
								  fComplierReleaseCheck.setEnabled(checkValue(INTR_COMPLIANCE_FOLLOWS_EE, USER_CONF) || checkValue(INTR_COMPLIANCE_FOLLOWS_EE, DISABLED));

(This goes back to bug 527569 - 2 commits).


Next, when I set release=enabled in .settings/org.eclipse.jdt.core.prefs, still release was not used on this path:

JRTUtil.getJrtSystem(File, String) line: 108	
JRTUtil.getJrtSystem(File) line: 104	
JRTUtil.getModulesDeclaringPackage(File, String, String) line: 177	
ClasspathJrtWithReleaseOption(ClasspathJrt).getModulesDeclaringPackage(String, String) line: 254	

JRTUtil does not know about the #release value correctly set in ClasspathJrtWithReleaseOption. 
=> This is an obvious bug in JDT/Core


Beyond that, the --release feature is flawed by design. Search for JDT bugs mentioning ct.sym and you'll see that JDT has no fair chance to correctly implement this feature. In particular, we recommend to use that feature only with JDK > 11, well actually, you'll probably need the JDK that was most recent at the time a given Eclipse version was released. So in order to gain backward compatibility we got a complete version lock. Go figure.


The mentioned recommendation against --release 11 also has a finger in the pie: ClasspathJrtWithReleaseOption refuses to use release information on some paths if !this.isJRE12Plus.


Good luck.
Comment 6 Stephan Herrmann CLA 2020-02-06 09:57:46 EST
Moreover I couldn't reproduce how you created bytecode mentioning java.lang.Math.floorDiv(JI)J I always get java/lang/Math.floorDiv:(JJ)J