Skip to content

NullPointerException when using WorkspaceFolders in LSP initialization request #2697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jnt0r opened this issue Jun 10, 2023 · 10 comments
Open

Comments

@jnt0r
Copy link
Contributor

jnt0r commented Jun 10, 2023

As soon as I set the WorkspaceFolders Property in the LSP initialization request, I get a NullPointerException in the xtext LSP server.
I tried different values for the property in different formats, but I always get the same exception.

java.util.concurrent.CompletionException: java.lang.NullPointerException
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:331)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:346)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:632)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2088)
	at org.eclipse.xtext.ide.server.concurrent.AbstractRequest.logAndCompleteExceptionally(AbstractRequest.java:73)
	at org.eclipse.xtext.ide.server.concurrent.WriteRequest.run(WriteRequest.java:55)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

Caused by: java.lang.NullPointerException
	at java.base/java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1011)
	at java.base/java.util.concurrent.ConcurrentHashMap.put(ConcurrentHashMap.java:1006)
	at org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions.setContainer(ChunkedResourceDescriptions.java:92)
	at org.eclipse.xtext.ide.server.ProjectManager.createNewResourceSet(ProjectManager.java:145)
	at org.eclipse.xtext.ide.server.ProjectManager.createFreshResourceSet(ProjectManager.java:155)
	at org.eclipse.xtext.ide.server.ProjectManager.newBuildRequest(ProjectManager.java:124)
	at org.eclipse.xtext.ide.server.ProjectManager.doBuild(ProjectManager.java:106)
	at org.eclipse.xtext.ide.server.ProjectManager.doInitialBuild(ProjectManager.java:98)
	at org.eclipse.xtext.ide.server.BuildManager.doInitialBuild(BuildManager.java:164)
	at org.eclipse.xtext.ide.server.WorkspaceManager.refreshWorkspaceConfig(WorkspaceManager.java:254)
	at org.eclipse.xtext.ide.server.WorkspaceManager.initialize(WorkspaceManager.java:173)
	at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$0(LanguageServerImpl.java:239)
	at org.eclipse.xtext.ide.server.concurrent.WriteRequest.run(WriteRequest.java:50)
	... 5 more
@cdietrich
Copy link
Contributor

Can you provide a reproducer unit test

@jnt0r
Copy link
Contributor Author

jnt0r commented Jun 11, 2023

I try to. I don't have a working xtext workspace yet and have to set it up first.
I tested it with the simple greetings starter DSL and the ballerina/lsp4intellij Plugin (newest version from master).

@cdietrich
Copy link
Contributor

cdietrich commented Jun 11, 2023

you should be able to create a test in a new mydsl project
alternatively you can try to debug the server and find out why it creates project with no names e.g.
MultiRootWorkspaceConfigFactory

@jnt0r
Copy link
Contributor Author

jnt0r commented Jun 11, 2023

I created a sample project https://github.com/jnt0r/xtext-npe-reproducable
Test is located here https://github.com/jnt0r/xtext-npe-reproducable/blob/master/org.xtext.example.mydsl.tests/src/org/xtext/example/mydsl/tests/MyLSPWorkspaceFoldersTest.java

I created multiple tests and figured out that it seems to depend on the name of the WorkspaceFolder.
Is this field really required? Wouldn't it be more convenient to throw dedicated errors instead of a NullPointerException?
I read that the WorkspaceFolder name defaults to the name of the specified folder in the provided uri.

@cdietrich
Copy link
Contributor

Xtext try’s to provide a project name from a folder name and currently we at lease need some name
I don’t know why we don’t throw a dedicated error. Needs to be looked at

@cdietrich
Copy link
Contributor

@jnt0r
Copy link
Contributor Author

jnt0r commented Jun 11, 2023

I got the optional thing from the LSP4J documentation: https://www.javadoc.io/static/org.eclipse.lsp4j/org.eclipse.lsp4j/0.21.0/org/eclipse/lsp4j/WorkspaceFolder.html
I will also address this at the lsp4intellij project to also send the name, as it is not optional in the LSP specification.

@cdietrich
Copy link
Contributor

maybe should be fixed in lsp4j

@cdietrich
Copy link
Contributor

created eclipse-lsp4j/lsp4j#741

@jnt0r
Copy link
Contributor Author

jnt0r commented Sep 13, 2023

eclipse-lsp4j/lsp4j#741 has been fixed and closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants