Skip to content

feat: remove "initializeResult unexpectedly null after initialization" exception#1524

Merged
rubenporras merged 1 commit intoeclipse-lsp4e:mainfrom
rubenporras:reduceFailures
Apr 20, 2026
Merged

feat: remove "initializeResult unexpectedly null after initialization" exception#1524
rubenporras merged 1 commit intoeclipse-lsp4e:mainfrom
rubenporras:reduceFailures

Conversation

@rubenporras
Copy link
Copy Markdown
Contributor

@rubenporras rubenporras commented Apr 17, 2026

this reduces the number of exceptions during LSP4E operations. As an
example of such an exception is:

!ENTRY org.eclipse.lsp4e 4 0 2026-04-20 09:22:31.360
!MESSAGE java.lang.IllegalStateException: serverCapabilities unexpectedly null after initialization
!STACK 0
java.util.concurrent.CompletionException: java.lang.IllegalStateException: serverCapabilities unexpectedly null after initialization
at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:368)
at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1189)
at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2341)
at org.eclipse.lsp4e.LanguageServerWrapper.getServerCapabilitiesAsync(LanguageServerWrapper.java:1120)
at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.filter(LanguageServers.java:282)
...
at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.getServers(LanguageServers.java:290)
at org.eclipse.lsp4e.LanguageServers.executeOnServers(LanguageServers.java:441)
at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:92)
at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:75)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingBase.collectLinkedEditingRanges(LSPLinkedEditingBase.java:72)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:168)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:156)
at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.lambda$0(LSPLinkedEditingReconcilingStrategy.java:134)
...

Copy link
Copy Markdown
Contributor

@FlorianKroiss FlorianKroiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look ok, but can you clarify which exceptions you want to avoid?

Comment on lines 60 to 69
if (capabilities != null) {
if (isDocumentRangeFormattingSupported(capabilities) && (textSelection.getLength() > 0 || !isDocumentFormattingSupported(capabilities))) {
return (CompletableFuture<@Nullable List<? extends TextEdit>>) ls.getTextDocumentService()
.rangeFormatting(rangeParams);
} else if (isDocumentFormattingSupported(capabilities)) {
return (CompletableFuture<@Nullable List<? extends TextEdit>>) ls.getTextDocumentService()
.formatting(params);
}
}
return CompletableFuture.completedFuture(null);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When having both a then and else branch, I like to avoid negations in the condition.
So similar to you other changes:

if (capabilities == null){
    returnCompletableFuture.completedFuture(null);
}
// ...else case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to minimize the number of return statemens but I can see that both are valid aproaches, so I have followed your suggestion.

// This can happen if the server shuts down immediately after initialization,
// but before this callback was invoked.
return CompletableFuture.failedFuture(
new IllegalStateException("initializeResult unexpectedly null after initialization")); //$NON-NLS-1$
Copy link
Copy Markdown
Contributor

@FlorianKroiss FlorianKroiss Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming these are the errors you wanted to get rid of?

exception

this reduces the number of exceptions during LSP4E operations. As an
example of such an exception is:

!ENTRY org.eclipse.lsp4e 4 0 2026-04-20 09:22:31.360
!MESSAGE java.lang.IllegalStateException: serverCapabilities
unexpectedly null after initialization
!STACK 0
java.util.concurrent.CompletionException:
java.lang.IllegalStateException: serverCapabilities unexpectedly null
after initialization
	at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:368)
	at java.base/java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:1189)
	at java.base/java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2341)
	at org.eclipse.lsp4e.LanguageServerWrapper.getServerCapabilitiesAsync(LanguageServerWrapper.java:1120)
	at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.filter(LanguageServers.java:282)
...
	at org.eclipse.lsp4e.LanguageServers$LanguageServerDocumentExecutor.getServers(LanguageServers.java:290)
	at org.eclipse.lsp4e.LanguageServers.executeOnServers(LanguageServers.java:441)
	at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:92)
	at org.eclipse.lsp4e.LanguageServers.collectAll(LanguageServers.java:75)
	at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingBase.collectLinkedEditingRanges(LSPLinkedEditingBase.java:72)
	at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:168)
	at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.updateLinkedEditing(LSPLinkedEditingReconcilingStrategy.java:156)
	at org.eclipse.lsp4e.operations.linkedediting.LSPLinkedEditingReconcilingStrategy.lambda$0(LSPLinkedEditingReconcilingStrategy.java:134)
	...
@rubenporras rubenporras changed the title feat: reduce number of exceptions if LS fails to start feat: remove "initializeResult unexpectedly null after initialization" exception Apr 20, 2026
@rubenporras rubenporras merged commit 86e8927 into eclipse-lsp4e:main Apr 20, 2026
12 of 16 checks passed
@rubenporras rubenporras deleted the reduceFailures branch April 20, 2026 08:40
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

Successfully merging this pull request may close these issues.

2 participants