redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

NullPointerException during compilation #3239

Open Skylark95 opened 1 year ago

Skylark95 commented 1 year ago

Language server throws NullPointerException when building project, resulting in extension crash and no Intellisense:

java.lang.NullPointerException: Cannot read field "scope" because "this.units[i]" is null
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:531)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:562)
    at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:344)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.accept(CompilationUnitResolver.java:190)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.accept(CompilationUnitResolver.java:185)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:346)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:276)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.findImport(CompilationUnitScope.java:585)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.findSingleImport(CompilationUnitScope.java:657)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInImports(CompilationUnitScope.java:486)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:559)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1311)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:790)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1245)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:868)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:294)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    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.ls.core.internal.handlers.InlayHintsHandler.inlayHint(InlayHintsHandler.java:59)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$54(JDTLanguageServer.java:1154)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
Environment
Steps To Reproduce
  1. Open offending project and run Java: Rebuild Projects
  2. Open any file for editing and the error will occur.

I cannot include sample project unfortunately due to company policy but I have included the necessary logs. The error does not appear to occur on all projects, just certain ones.

extension.log

Current Result
Expected Result
Additional Informations
snjeza commented 1 year ago

@Skylark95 You can try to add

"java.inlayHints.parameterNames.enabled": "none",

to your settings.json

Skylark95 commented 1 year ago

@snjeza I added the mentioned config and still get the same behavior and exception on v1.21.0

snjeza commented 1 year ago

@Skylark95 Could you check your workspace settings.json? This is an upstream jdt.core issue.

snjeza commented 1 year ago

@Skylark95 Could you provide your pom.xml or build.gradle?

Skylark95 commented 1 year ago

@snjeza Unfortunately unable to get permission from my company to provide that. :(

bdux commented 1 year ago

@Skylark95 ~Could you check your workspace settings.json?~ This is an upstream jdt.core issue.

I can't find anything regarding this in jdt core issues. Was this adressed?

snjeza commented 1 year ago

@Skylark95 Could you test Java LS 1.24.3? It includes the fix from https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1376

abhinavbhatia5 commented 4 months ago

use Optional.ofNullable() for "this.units[i]" .