eclipse-xtext / eclipse-xtext/xtext
NullPointerException when using no rootURI or WorkspaceFolders in LSP initialization request
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
For initialize messages that do not provide any rootPath, rootURI, or workspaceFolders, the workspaceManager is called and throws a NPE. According to the LSP documentation, null fields for all three of these are allowed, yet this is a possible stack trace that occurs during initialization (only relevant part shown):
Caused by: java.lang.NullPointerException: Cannot invoke "org.eclipse.emf.common.util.URI.isFile()" because "uri" is null
at org.eclipse.xtext.util.UriExtensions.withEmptyAuthority(UriExtensions.java:144)
at org.eclipse.xtext.ide.server.UriExtensions.toUriString(UriExtensions.java:27)
at org.eclipse.xtext.ide.server.WorkspaceManager.initialize(WorkspaceManager.java:154)
at org.eclipse.xtext.ide.server.LanguageServerImpl.lambda$0(LanguageServerImpl.java:242)
at org.eclipse.xtext.ide.server.concurrent.WriteRequest.run(WriteRequest.java:50)
... 5 more
I dug around the code a little and can pinpoint this issue being here since #2801. These are the corresponding lines causing the issue:
LanguageServerImpl#L235-L252
Before the update, null values for the folders/uri caused the code to go through the first part in the if, because workspace folders are generally supported. Then, an empty workspace folder list was created, making the workspace initialization happy.
However, now the clientSupportsWorkspaceFolders check returns false because there are no workspace folders, thus the code takes the second path. In this path, the baseDir gets evaluated to null, failing the subsequent workspace initialization.
I do not know what the correct path here would be - I think either the clientSupportsWorkspaceFolders check should return true if they are generally supported, even if there are no workspace folders in the initialization, or the else case should notice that there is no baseDir and handle the null case appropriately.
For now, I fixed the problem in my system by overwriting the clientSupportsWorkspaceFolders method to always return true for now.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at LanguageServerImpl.java lines 235-252 and trace the initialization call into WorkspaceManager.initialize and the URI conversion shown in the stack trace. Reproduce an initialize request with null rootPath, rootURI, and workspaceFolders, then determine the appropriate handling path. Done means initialization completes without a NullPointerException for that valid request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100