From a3f691c733b8a0c483554d42268186e61ee0d028 Mon Sep 17 00:00:00 2001 From: Junichi Yamamoto Date: Fri, 13 Dec 2024 13:50:44 +0900 Subject: [PATCH] Prevent NPE - Do not return `null` in `getOccurrences()` - See GH-8028 --- .../modules/php/editor/csl/OccurrencesFinderImpl.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java b/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java index 12f817823d00..066d610920c0 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/csl/OccurrencesFinderImpl.java @@ -68,7 +68,8 @@ public void setCaretPosition(int position) { @Override public Map getOccurrences() { - return range2Attribs; + // must not return null + return Collections.unmodifiableMap(range2Attribs); } @Override @@ -99,9 +100,11 @@ public void run(Result result, SchedulerEvent event) { return; } - if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true) || localRange2Attribs.size() > 0) { - //store the occurrences if not empty, return null in getOccurrences() otherwise + if (!node.getBoolean(MarkOccurencesSettings.KEEP_MARKS, true) || !localRange2Attribs.isEmpty()) { + //store the occurrences if not empty range2Attribs = localRange2Attribs; + } else { + range2Attribs = Collections.emptyMap(); } }