You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by sk...@apache.org on 2021/07/30 11:27:20 UTC

[netbeans] branch master updated: [NETBEANS-5841] prevent NPE in LSP client using a Python Language Server (#3078)

This is an automated email from the ASF dual-hosted git repository.

skygo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new ee3624e  [NETBEANS-5841] prevent NPE in LSP client using a Python Language Server (#3078)
ee3624e is described below

commit ee3624e93425ddbea1e1174ff745f363493cb65f
Author: Michael Küttner <mi...@dmos2002.de>
AuthorDate: Fri Jul 30 13:27:04 2021 +0200

    [NETBEANS-5841] prevent NPE in LSP client using a Python Language Server (#3078)
    
    * [NETBEANS-5841] prevent NPE in MarkOccurrences
    
    * [NETBEANS-5841] fixed formatting
---
 .../lsp/client/bindings/MarkOccurrences.java       | 31 +++++++++++++---------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/MarkOccurrences.java b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/MarkOccurrences.java
index 06f0704..751b932 100644
--- a/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/MarkOccurrences.java
+++ b/ide/lsp.client/src/org/netbeans/modules/lsp/client/bindings/MarkOccurrences.java
@@ -99,8 +99,11 @@ public class MarkOccurrences implements BackgroundTask, CaretListener, PropertyC
         }
         String uri = Utils.toURI(file);
         try {
-            List<? extends DocumentHighlight> highlights =
-                    server.getTextDocumentService().documentHighlight(new DocumentHighlightParams(new TextDocumentIdentifier(uri), Utils.createPosition(doc, caretPos))).get();
+            List<? extends DocumentHighlight> highlights
+                    = server.getTextDocumentService().documentHighlight(new DocumentHighlightParams(new TextDocumentIdentifier(uri), Utils.createPosition(doc, caretPos))).get();
+            if (highlights == null) {
+                return result;
+            }
             for (DocumentHighlight h : highlights) {
                 result.addHighlight(Utils.getOffset(doc, h.getRange().getStart()), Utils.getOffset(doc, h.getRange().getEnd()), attr);
             }
@@ -113,14 +116,14 @@ public class MarkOccurrences implements BackgroundTask, CaretListener, PropertyC
 
     private AttributeSet getColoring(Document doc) {
         FontColorSettings fcs = MimeLookup.getLookup(NbEditorUtilities.getMimeType(doc)).lookup(FontColorSettings.class);
-        
+
         if (fcs == null) {
             //in tests:
             return AttributesUtilities.createImmutable();
         }
-        
+
         assert fcs != null;
-        
+
         return fcs.getTokenFontColors("mark-occurrences");
     }
 
@@ -155,31 +158,33 @@ public class MarkOccurrences implements BackgroundTask, CaretListener, PropertyC
                 public void insertUpdate(DocumentEvent e) {
                     bagFin.removeHighlights(e.getOffset(), e.getOffset(), false);
                 }
+
                 public void removeUpdate(DocumentEvent e) {
                     bagFin.removeHighlights(e.getOffset(), e.getOffset(), false);
                 }
-                public void changedUpdate(DocumentEvent e) {}
+
+                public void changedUpdate(DocumentEvent e) {
+                }
             };
 
             doc.addDocumentListener(l);
 
             if (stream instanceof DataObject) {
-                Logger.getLogger("TIMER").log(Level.FINE, "LSP Client MarkOccurrences Highlights Bag", new Object[] {((DataObject) stream).getPrimaryFile(), bag}); //NOI18N
-                Logger.getLogger("TIMER").log(Level.FINE, "LSP Client MarkOccurrences Highlights Bag Listener", new Object[] {((DataObject) stream).getPrimaryFile(), l}); //NOI18N
+                Logger.getLogger("TIMER").log(Level.FINE, "LSP Client MarkOccurrences Highlights Bag", new Object[]{((DataObject) stream).getPrimaryFile(), bag}); //NOI18N
+                Logger.getLogger("TIMER").log(Level.FINE, "LSP Client MarkOccurrences Highlights Bag Listener", new Object[]{((DataObject) stream).getPrimaryFile(), l}); //NOI18N
             }
         }
 
         return bag;
     }
-    
-    @MimeRegistration(mimeType="", service=HighlightsLayerFactory.class)
+
+    @MimeRegistration(mimeType = "", service = HighlightsLayerFactory.class)
     public static class HighlightsLayerFactoryImpl implements HighlightsLayerFactory {
 
         public HighlightsLayer[] createLayers(HighlightsLayerFactory.Context context) {
-            return new HighlightsLayer[] {
+            return new HighlightsLayer[]{
                 //the mark occurrences layer should be "above" current row and "below" the search layers:
-                HighlightsLayer.create(MarkOccurrences.class.getName(), ZOrder.SHOW_OFF_RACK.forPosition(20), true, MarkOccurrences.getHighlightsBag(context.getDocument())),
-            };
+                HighlightsLayer.create(MarkOccurrences.class.getName(), ZOrder.SHOW_OFF_RACK.forPosition(20), true, MarkOccurrences.getHighlightsBag(context.getDocument())),};
         }
 
     }

---------------------------------------------------------------------
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