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

Bug 574362

Summary: [junit] Can't run tests on JDK older 1.8
Product: [Eclipse Project] JDT Reporter: KP <pollentierk>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jimmy.praet, loskutov, noopur_gupta, robert.anderlik
Version: 4.20   
Target Milestone: ---   
Hardware: PC   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=571009
Whiteboard:

Description KP CLA 2021-06-21 09:40:55 EDT
Since 2021-06, JUnit tests targeted for older Java versions can't run using that older JRE anymore.
They only run when using JRE for Java 8 or later.

Until 2021-03 that worked fine with an older JRE however.

Even though Eclipse 2021-03 itself was happily running on JDK 11, for Java (normal Java an OSGi) projects that still need to target older Java versions (Java 7, even Java 5), it was perfectly possible in Eclipse 2021-03 to run those JUnit tests with the Runtime JRE executable being an actual JDK 5 or JDK 7 javaw.exe
(Which makes sense, as those unit tests can then catch possible JDK dependent subtleties, e.g. related to version-specific API, to version-specific system properties, etc.)


Now since 2021-06 this is broken.
E.g. for a project which still target Java version Java 7 as minimal requirement, and the runtime JRE for the junit tests being an actual Java 7 JDK, we get this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jdt/internal/junit/runner/RemoteTestRunner : Unsupported major.minor version 52.0
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)


So somehow, 2021-06 suddenly requires the unit tests to run only on Java 8 or later?

Then what's the point of selecting the Runtime JRE in the Run Configuration, or allowing to select a version older than JavaSE-1.8 ?
And how can we now test again an older JRE?
Comment 1 Andrey Loskutov CLA 2021-06-21 09:57:22 EDT
Probably regression (or a deliberate choice) from bug 571009.

Noopur, is running JUnit tests on Java < 8 is supported by Eclipse 4.20?
Comment 2 Andrey Loskutov CLA 2021-06-21 10:19:04 EDT
(In reply to Andrey Loskutov from comment #1)
> Probably regression (or a deliberate choice) from bug 571009.
> 
> Noopur, is running JUnit tests on Java < 8 is supported by Eclipse 4.20?

By changing org.eclipse.jdt.junit.runtime compiler settings like below I'm able to run the test on Java 7 (debugging IDE in IDE)

diff --git a/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs
index e57b044..5429dae 100644
--- a/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs
@@ -28,5 +28,5 @@
 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.targetPlatform=1.7
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=1.7
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
@@ -135,3 +135,3 @@
 org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.source=1.7
 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false


I haven't verified if maven/tycho is able to build on Java 8 with target 7, but that could be a possible solution.

Another solution would be move to Java 11 and specify --release 7:

diff --git a/org.eclipse.jdt.junit.runtime/.classpath b/org.eclipse.jdt.junit.runtime/.classpath
index eca7bdb..4a00bec 100644
--- a/org.eclipse.jdt.junit.runtime/.classpath
+++ b/org.eclipse.jdt.junit.runtime/.classpath
@@ -2,3 +2,7 @@
 <classpath>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
+		<attributes>
+			<attribute name="module" value="true"/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
diff --git a/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs
index e57b044..13b87d2 100644
--- a/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.jdt.junit.runtime/.settings/org.eclipse.jdt.core.prefs
@@ -28,5 +28,5 @@
 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.targetPlatform=1.7
 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.compliance=1.7
 org.eclipse.jdt.core.compiler.debug.lineNumber=generate
@@ -134,4 +134,4 @@
 org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=1.7
 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
diff --git a/org.eclipse.jdt.junit.runtime/META-INF/MANIFEST.MF b/org.eclipse.jdt.junit.runtime/META-INF/MANIFEST.MF
index 86c2f9c..688b8c0 100644
--- a/org.eclipse.jdt.junit.runtime/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.junit.runtime/META-INF/MANIFEST.MF
@@ -5,3 +5,3 @@
 Bundle-SymbolicName: org.eclipse.jdt.junit.runtime;singleton:=true
-Bundle-Version: 3.6.0.qualifier
+Bundle-Version: 3.7.0.qualifier
 Bundle-Vendor: %providerName
@@ -16,2 +16,2 @@
 Require-Bundle: org.junit;bundle-version="3.8.2"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-RequiredExecutionEnvironment: JavaSE-11
Comment 3 Noopur Gupta CLA 2021-06-21 10:24:38 EDT
(In reply to Andrey Loskutov from comment #1)
> Noopur, is running JUnit tests on Java < 8 is supported by Eclipse 4.20?
No. All options suggested in comment #2 were discussed with the team and it was a deliberate decision to move compiler settings also to 1.8 (done via bug 571009).

(In reply to KP from comment #0)
> Then what's the point of selecting the Runtime JRE in the Run Configuration,
> or allowing to select a version older than JavaSE-1.8 ?
This should be handled as an enhancement / bug fix.

> And how can we now test again an older JRE?
You will need Eclipse 4.19 or older.
Comment 4 Andrey Loskutov CLA 2021-06-30 13:32:47 EDT
*** Bug 574567 has been marked as a duplicate of this bug. ***
Comment 5 Julian Honnen CLA 2021-07-07 10:28:53 EDT
*** Bug 574714 has been marked as a duplicate of this bug. ***