-
Notifications
You must be signed in to change notification settings - Fork 159
Description
We use the ASTParser in our code to convert some old Java Source Files (javax -> jakarta).
Our code runs in an OSGI runtime environment, so Platform.isRunning() returns true.
But we do not start the org.eclipse.jdt.core bundle because of performance reasons.
In this case the following exception is thrown:
java.lang.ExceptionInInitializerError
at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:4619)
at org.eclipse.jdt.core.dom.ASTParser.initializeDefaults(ASTParser.java:330)
at org.eclipse.jdt.core.dom.ASTParser.(ASTParser.java:236)
at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java:136)
...
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.core.runtime.Plugin.getStateLocation()" because the return value of "org.eclipse.jdt.core.JavaCore.getPlugin()" is null
at org.eclipse.jdt.internal.core.search.indexing.IndexManager.getJavaPluginWorkingLocation(IndexManager.java:610)
at org.eclipse.jdt.internal.core.search.indexing.IndexManager.getSavedIndexesDirectory(IndexManager.java:614)
at org.eclipse.jdt.internal.core.search.indexing.IndexManager.(IndexManager.java:115)
at org.eclipse.jdt.internal.core.JavaModelManager.(JavaModelManager.java:1811)
at org.eclipse.jdt.internal.core.JavaModelManager.(JavaModelManager.java:1171)
This is because the Index Manager tries to access the JavaCore.getPlugin() to get the working location. Since the bundle org.eclipse.jdt.core is not started, the getPlugin method returns null.
In the class JavaModelManager, there is a check if the Platform is running, in which case the IndexManager is initialized. If it is not running, nothing is initialized to allow the ASTParser to be used in non-OSGI environments.
Fix: Instead of checking if the Platform is running it should be checked if the JavaCore.getPlugin() return null or not.
I will provide a PR for the fix.