Skip to content

Commit 421f27c

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 #4399
1 parent 287e82f commit 421f27c

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

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

Lines changed: 12 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, tje JCL21 wil 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");
@@ -136,6 +144,8 @@ public class D {
136144
void m(B b) {
137145
// Calling method m only available from Java 21+
138146
b.m();
147+
// Calling a JDK class should work
148+
System.out.println("Testme");
139149
}
140150
}
141151
""";

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)