LSP Server computeDiagnostics overwrites ERRORS with HINTS
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Open java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java and inspect computeDiagnostics around line 2150, focusing on how ERRORS and HINTS are returned together. Verify that a request containing both kinds preserves both diagnostic sets in the completed result, and check the relevant LSP diagnostics tests if available.
Written by the indexing model from the issue text.
Description
Apache NetBeans version
Apache NetBeans 30
What happened
Bug Report: LSP Server computeDiagnostics overwrites ERRORS with HINTS
Component
Java Language Server (java.lsp.server)
File
java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
Description
There is a logic flaw in the computeDiagnostics method inside TextDocumentServiceImpl.java that causes valid Java compilation errors to randomly disappear from the client or be completely overwritten by minor code hints.
When the LSP client requests both ERRORS and HINTS simultaneously (or when they are computed in the same batch), the method retrieves the errors successfully but fails to properly merge them with the hints. Instead of aggregating both into a single List<Diagnostic>, the result list was being overwritten.
The Bug
In the original implementation of computeDiagnostics(String uri, EnumSet<ErrorProvider.Kind> types) (around line 2150):
List<Diagnostic> result = Collections.emptyList();
if (types.contains(ErrorProvider.Kind.ERRORS)) {
result = computeDiags(uri, -1, ErrorProvider.Kind.ERRORS, originalVersion, docHolder);
}
if (types.contains(ErrorProvider.Kind.HINTS)) {
// BUG: This completely overwrites the ERRORS computed above!
result = computeDiags(uri, -1, ErrorProvider.Kind.HINTS, originalVersion, docHolder);
}
r.complete(result);
Because result is assigned directly without appending, if both ERRORS and HINTS are requested, the HINTS computation completely eradicates the ERRORS from the final payload sent back to the LSP client.
Proposed Fix
The result collection must be instantiated as an ArrayList and both types of diagnostics must be merged into it using .addAll().
List<Diagnostic> result = new ArrayList<>();
if (types.contains(ErrorProvider.Kind.ERRORS)) {
result.addAll(computeDiags(uri, -1, ErrorProvider.Kind.ERRORS, originalVersion, docHolder));
}
if (types.contains(ErrorProvider.Kind.HINTS)) {
result.addAll(computeDiags(uri, -1, ErrorProvider.Kind.HINTS, originalVersion, docHolder));
}
r.complete(result);
Impact
Without this fix, any client-side tool or background scanner that requests full diagnostics for a file via the nbls.get.diagnostics command will receive an incomplete picture of the file's health, leading to valid compilation errors being hidden from the developer.
Language / Project Type / NetBeans Component
No response
How to reproduce
When the LSP client requests both ERRORS and HINTS simultaneously (or when they are computed in the same batch), the method retrieves the errors successfully but fails to properly merge them with the hints. Instead of aggregating both into a single List, the result list was being overwritten.
Did this work correctly in an earlier version?
No / Don't know
Operating System
Windows
JDK
26
Apache NetBeans packaging
Apache NetBeans binary zip
Anything else
this is related to this Pull Request for Netbeans-vscode:
https://github.com/apache/netbeans-vscode/pull/33
Are you willing to submit a pull request?
No
- Dominant language
- Java
- Stars
- 3.1k
- Forks
- 933
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 22
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.
More from apache/netbeans
-
LSP
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Contribution welcome kind:feature Platform
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Editor Java kind:feature needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
The main Options dialog window has buttons with OK on the left instead of on the right on Linux Openkind:bug needs:triage os:linux os:macos Platform UI
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
-
kind:bug needs:triage
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
area/frontend
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100