Skip to content

Commit 12fad88

Browse files
committed
Take release level into account when check for java9
Currently in SearchableEnvironment we only check if the project level is larger java9plus but when constructing a release specific SearchableEnvironment this needs to take the release option into account instead. Fix eclipse-jdt#4399
1 parent e003a17 commit 12fad88

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerMultiReleaseTests.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import junit.framework.Test;
44
import org.eclipse.core.runtime.CoreException;
5+
import org.eclipse.core.runtime.IPath;
56
import org.eclipse.core.runtime.NullProgressMonitor;
67
import org.eclipse.jdt.core.IClasspathAttribute;
78
import org.eclipse.jdt.core.IClasspathEntry;
@@ -45,9 +46,16 @@ public IProblemRequestor getProblemRequestor(ICompilationUnit unit) {
4546
@Override
4647
public void setUpSuite() throws Exception {
4748
super.setUpSuite();
48-
49+
//Because we use 1.8 compliance on the project, the JCL21 will not be setup automatically so we need to to it explicitly.
50+
if (JavaCore.getClasspathVariable("JCL_21_LIB") == null) {
51+
setupExternalJCL("jclMin21");
52+
JavaCore.setClasspathVariables(
53+
new String[] {"JCL_21_LIB", "JCL_21_SRC", "JCL_SRCROOT"},
54+
new IPath[] {getExternalJCLPath("21"), getExternalJCLSourcePath("21"), getExternalJCLRootSourcePath()},
55+
null);
56+
}
4957
IJavaProject mrproject = createJavaProject("ReconcilerMR", new String[] { "src", "src9", "src21" },
50-
new String[] { "JCL18_LIB" }, "bin");
58+
new String[] { "JCL_21_LIB" }, "bin");
5159
createFolder("/ReconcilerMR/src/p");
5260
createFolder("/ReconcilerMR/src9/p");
5361
createFolder("/ReconcilerMR/src21/p");
@@ -112,6 +120,9 @@ void m(B b) {
112120
mrproject.setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED);
113121
mrproject.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE);
114122
mrproject.setOption(JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.WARNING);
123+
mrproject.setOption(JavaCore.COMPILER_COMPLIANCE, "1.8");
124+
mrproject.setOption(JavaCore.COMPILER_SOURCE, "1.8");
125+
mrproject.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.8");
115126
}
116127

117128
@Override
@@ -136,6 +147,8 @@ public class D {
136147
void m(B b) {
137148
// Calling method m only available from Java 21+
138149
b.m();
150+
// Calling a JDK class should work
151+
System.out.println("Running " + System.getProperty("java.version"));
139152
}
140153
}
141154
""";

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public SearchableEnvironment(JavaProject project, org.eclipse.jdt.core.ICompilat
115115
|| !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true));
116116
this.workingCopies = workingCopies;
117117
this.nameLookup = project.newNameLookup(workingCopies, excludeTestCode);
118-
boolean java9plus = JavaCore.callReadOnly(() -> CompilerOptions
118+
boolean java9plus = release >=JavaProject.FIRST_MULTI_RELEASE || JavaCore.callReadOnly(() -> CompilerOptions
119119
.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true)) >= ClassFileConstants.JDK9);
120120
if (java9plus) {
121121
this.knownModuleLocations = new HashMap<>();

0 commit comments

Comments
 (0)