Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.lsp4e.operations.symbols;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -230,10 +231,10 @@ private static List<WorkspaceSymbol> toWorkspaceSymbols(@Nullable List<? extends
return res;
}

static List<? extends WorkspaceSymbol> eitherToWorkspaceSymbols(
static List<@Nullable ? extends WorkspaceSymbol> eitherToWorkspaceSymbols(
final @Nullable Either<List<? extends SymbolInformation>, List<@Nullable ? extends WorkspaceSymbol>> source) {
return source == null //
? List.of()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does List.of not work?

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.

Not for me, then I get the marker:

Null type mismatch (type annotations): required '@nonnull List<@nullable ? extends WorkspaceSymbol>' but this expression has type '@nonnull List<@nonnull WorkspaceSymbol>'

It looks to me that the JDT does not like than one is List.of() is guaranteed to be not null, and the other expression is Nullable.

I tried NullSafetyHelper.castNullable(List.of()) which also causes the JDT to complain.

It looks to me like a litimation of the JDT null analysis, or at least I do not understand why it is complaining.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll check if this can be solved via a change to the external null annotations

Copy link
Copy Markdown
Member

@sebthom sebthom Nov 26, 2025

Choose a reason for hiding this comment

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

@rubenporras List.of has the contract that it only returns lists with non-null elements. But you can replace List.of with Collections.emptyList() and it should work.

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.

Is this because of the external null annotations? The signature in java looks equal to me

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes the EEAs make the actual contract of List.of visible.

: source.map(LSPSymbolInWorkspaceDialog::toWorkspaceSymbols, Function.identity());
? Collections.emptyList()
: source.map(LSPSymbolInWorkspaceDialog::toWorkspaceSymbols, Function.identity());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -69,7 +70,7 @@ public QuickAccessElement[] computeElements(String query, IProgressMonitor monit
CompletableFuture.allOf(usedLanguageServerWrappers.stream()
.map(w -> w.execute(ls -> ls.getWorkspaceService().symbol(params).thenAcceptAsync((@Nullable Either<List<? extends SymbolInformation>, List<@Nullable ? extends WorkspaceSymbol>> symbols) -> {
if (symbols != null) {
res.addAll(LSPSymbolInWorkspaceDialog.eitherToWorkspaceSymbols(symbols).stream().map(WorkspaceSymbolQuickAccessElement::new)
res.addAll(LSPSymbolInWorkspaceDialog.eitherToWorkspaceSymbols(symbols).stream().filter(Objects::nonNull).map(WorkspaceSymbolQuickAccessElement::new)
.toList());
}
}))).toArray(CompletableFuture[]::new)).get(1, TimeUnit.SECONDS);
Expand Down
Loading