Skip to content

Commit 1a9f0f8

Browse files
mickaelistriailoveeclipse
authored andcommitted
Avoid crash when resolving ICompilationUnit with unknown source version
When deciding whether to enable preview or not, check that source version is known, otherwise fail back to latest known version. Avoid using AST class which would trigger (undesired) exception in such case) Fixes #3929
1 parent 23b02c8 commit 1a9f0f8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.eclipse.jdt.internal.compiler.IProblemFactory;
4747
import org.eclipse.jdt.internal.compiler.SourceElementParser;
4848
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
49+
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
4950
import org.eclipse.jdt.internal.compiler.env.IElementInfo;
5051
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
5152
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
@@ -1583,7 +1584,7 @@ public Map<String, String> getCustomOptions() {
15831584
IJavaProject parentProject = getJavaProject();
15841585
Map<String, String> parentOptions = parentProject == null ? JavaCore.getOptions() : parentProject.getOptions(true);
15851586
if (JavaCore.ENABLED.equals(parentOptions.get(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES)) &&
1586-
AST.newAST(parentOptions).apiLevel() < AST.getJLSLatest()) {
1587+
CompilerOptions.versionToJdkLevel(parentOptions.getOrDefault(JavaCore.COMPILER_SOURCE, JavaCore.latestSupportedJavaVersion())) < ClassFileConstants.getLatestJDKLevel()) {
15871588
// Disable preview features for older Java releases as it causes the compiler to fail later
15881589
if (customOptions != null) {
15891590
customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.DISABLED);

0 commit comments

Comments
 (0)