You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sd...@apache.org on 2024/01/09 11:53:13 UTC
(netbeans) 03/03: Fixed potential race condition betweeen LSP requests and reportController.
This is an automated email from the ASF dual-hosted git repository.
sdedic pushed a commit to branch vsnetbeans_2003
in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 53e632e7e3068683519d985fc33f40647c3dcd8e
Author: Svata Dedic <sv...@oracle.com>
AuthorDate: Tue Jan 9 10:15:22 2024 +0100
Fixed potential race condition betweeen LSP requests and reportController.
---
.../server/protocol/TextDocumentServiceImpl.java | 38 ++++++++++++----------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
index 115f717dd2..0dd12e5ea1 100644
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
@@ -1914,23 +1914,27 @@ public class TextDocumentServiceImpl implements TextDocumentService, LanguageCli
new Exception("no NbCodeLanguageClient!").printStackTrace();
}
- diagnosticTasks.computeIfAbsent(uri, u -> {
- return BACKGROUND_TASKS.create(() -> {
- Document originalDoc = server.getOpenedDocuments().getDocument(uri);
- long originalVersion = documentVersion(originalDoc);
- List<Diagnostic> errorDiags = computeDiags(u, -1, ErrorProvider.Kind.ERRORS, originalVersion);
- if (documentVersion(originalDoc) == originalVersion) {
- publishDiagnostics(uri, errorDiags);
- BACKGROUND_TASKS.create(() -> {
- List<Diagnostic> hintDiags = computeDiags(u, -1, ErrorProvider.Kind.HINTS, originalVersion);
- Document doc = server.getOpenedDocuments().getDocument(uri);
- if (documentVersion(doc) == originalVersion) {
- publishDiagnostics(uri, hintDiags);
- }
- }).schedule(DELAY);
- }
- });
- }).schedule(DELAY);
+ // sync needed - this can be called also from reporterControl, from other that LSP request thread. The factory function just cretaes a stopped
+ // Task that is executed later.
+ synchronized (diagnosticTasks) {
+ diagnosticTasks.computeIfAbsent(uri, u -> {
+ return BACKGROUND_TASKS.create(() -> {
+ Document originalDoc = server.getOpenedDocuments().getDocument(uri);
+ long originalVersion = documentVersion(originalDoc);
+ List<Diagnostic> errorDiags = computeDiags(u, -1, ErrorProvider.Kind.ERRORS, originalVersion);
+ if (documentVersion(originalDoc) == originalVersion) {
+ publishDiagnostics(uri, errorDiags);
+ BACKGROUND_TASKS.create(() -> {
+ List<Diagnostic> hintDiags = computeDiags(u, -1, ErrorProvider.Kind.HINTS, originalVersion);
+ Document doc = server.getOpenedDocuments().getDocument(uri);
+ if (documentVersion(doc) == originalVersion) {
+ publishDiagnostics(uri, hintDiags);
+ }
+ }).schedule(DELAY);
+ }
+ });
+ }).schedule(DELAY);
+ }
}
CompletableFuture<List<Diagnostic>> computeDiagnostics(String uri, EnumSet<ErrorProvider.Kind> types) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists