eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
165 stars 130 forks source link

"Missing System Library" exception in ASTParser #3298

Open ptziegler opened 2 days ago

ptziegler commented 2 days ago

This seems to be a regression introduced by https://github.com/eclipse-jdt/eclipse.jdt.core/commit/74d062b38d3003638127127cc5358dd9f79df0f4

To reproduce: Make sure compiler compliance is set to > 1.8 and open a Java file from a project without Java nature.

image

Stack Trace:

java.lang.IllegalStateException: Missing system library
    at org.eclipse.jdt.core.dom.ASTParser.checkForSystemLibrary(ASTParser.java:311)
    at org.eclipse.jdt.core.dom.ASTParser.getClasspath(ASTParser.java:272)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1299)
    at org.eclipse.jdt.core.dom.ASTParser.lambda$1(ASTParser.java:1178)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5694)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1178)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:918)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:294)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:286)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:199)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:189)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.lambda$0(SelectionListenerWithASTManager.java:149)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5694)
    at org.eclipse.jdt.internal.core.JavaModelManager.callReadOnly(JavaModelManager.java:5683)
    at org.eclipse.jdt.core.JavaCore.callReadOnly(JavaCore.java:6150)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:149)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: Java Model Exception: Error in Java Model (code 969): TestProject does not exist
    at org.eclipse.jdt.internal.core.JavaElement.newJavaModelException(JavaElement.java:556)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:234)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:569)
    at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:292)
    at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:278)
    at org.eclipse.jdt.internal.core.JavaProject.getJavaProjectElementInfo(JavaProject.java:2040)
    at org.eclipse.jdt.internal.core.JavaProject.newNameLookup(JavaProject.java:2775)
    at org.eclipse.jdt.internal.core.JavaProject.newNameLookup(JavaProject.java:2769)
    at org.eclipse.jdt.internal.core.JavaProject.newNameLookup(JavaProject.java:2787)
    at org.eclipse.jdt.internal.core.JavaProject.newNameLookup(JavaProject.java:2779)
    at org.eclipse.jdt.internal.core.JavaProject.findType(JavaProject.java:1681)
    at org.eclipse.jdt.internal.core.JavaProject.findType(JavaProject.java:1582)
    at org.eclipse.jdt.core.dom.ASTParser.checkForSystemLibrary(ASTParser.java:304)
    ... 19 more
ptziegler commented 2 days ago

See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3047 for context.

ptziegler commented 2 days ago

This check should probably only be done for proper Java projects?

jukzi commented 2 days ago

This seems to be a regression introduced by 74d062b

@stephan-herrmann can you take a look?