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

neilcsmith 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 fbe80af  [NETBEANS-4620] NullPointerException - finding occurrences
     new 412cee3  Merge pull request #2325 from junichi11/netbeans-4620
fbe80af is described below

commit fbe80af36f22ec1423857b7288f6097acb89b5e4
Author: Junichi Yamamoto <junich...@apache.org>
AuthorDate: Sun Aug 23 22:25:05 2020 +0900

    [NETBEANS-4620] NullPointerException - finding occurrences
    
    To avoid NPE, check new value is not `null` but `Caret`. If it's `null`, 
`BasicTextUI.editor` field may be `null`.
    
    ```
    java.lang.NullPointerException
        at 
java.desktop/javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1104)
        at 
java.desktop/javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1089)
        at 
java.desktop/javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:1065)
        at 
org.netbeans.modules.editor.search.SearchComboBoxEditor$ManageViewPositionListener.changed(SearchComboBoxEditor.java:290)
        at 
org.netbeans.modules.editor.search.SearchComboBoxEditor$ManageViewPositionListener.removeUpdate(SearchComboBoxEditor.java:277)
        at 
org.netbeans.lib.editor.util.swing.PriorityDocumentListenerList.removeUpdate(PriorityDocumentListenerList.java:91)
        at 
java.desktop/javax.swing.text.AbstractDocument.fireRemoveUpdate(AbstractDocument.java:261)
        at 
org.netbeans.editor.BaseDocument.fireRemoveUpdate(BaseDocument.java:1650)
        at org.netbeans.editor.BaseDocument.handleRemove(BaseDocument.java:1022)
        at 
org.netbeans.editor.BaseDocument$FilterBypassImpl.remove(BaseDocument.java:2639)
        at 
java.desktop/javax.swing.text.DocumentFilter.remove(DocumentFilter.java:79)
        at org.netbeans.editor.BaseDocument.remove(BaseDocument.java:935)
        at 
org.netbeans.modules.editor.search.SearchComboBoxEditor$3.propertyChange(SearchComboBoxEditor.java:137)
    ```
---
 .../modules/editor/search/SearchComboBoxEditor.java | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git 
a/ide/editor.search/src/org/netbeans/modules/editor/search/SearchComboBoxEditor.java
 
b/ide/editor.search/src/org/netbeans/modules/editor/search/SearchComboBoxEditor.java
index 45d303f..1edb26d 100644
--- 
a/ide/editor.search/src/org/netbeans/modules/editor/search/SearchComboBoxEditor.java
+++ 
b/ide/editor.search/src/org/netbeans/modules/editor/search/SearchComboBoxEditor.java
@@ -127,17 +127,16 @@ public class SearchComboBoxEditor implements 
ComboBoxEditor {
                 // selection is not removed when text is input via IME
                 // so, just remove it when the caret is changed
                 if ("caret".equals(evt.getPropertyName())) { // NOI18N
-                    if (evt.getOldValue() instanceof Caret) {
+                    if (evt.getOldValue() instanceof Caret
+                            && evt.getNewValue() instanceof Caret) { // 
NETBEANS-4620 check new value is not null but Caret
                         Caret oldCaret = (Caret) evt.getOldValue();
-                        if (oldCaret != null) {
-                            int dotPosition = oldCaret.getDot();
-                            int markPosition = oldCaret.getMark();
-                            if (dotPosition != markPosition) {
-                                try {
-                                    
editorPane.getDocument().remove(Math.min(markPosition, dotPosition), 
Math.abs(markPosition - dotPosition));
-                                } catch (BadLocationException ex) {
-                                    LOG.log(Level.WARNING, "Invalid removal 
offset: {0}", ex.offsetRequested()); // NOI18N
-                                }
+                        int dotPosition = oldCaret.getDot();
+                        int markPosition = oldCaret.getMark();
+                        if (dotPosition != markPosition) {
+                            try {
+                                
editorPane.getDocument().remove(Math.min(markPosition, dotPosition), 
Math.abs(markPosition - dotPosition));
+                            } catch (BadLocationException ex) {
+                                LOG.log(Level.WARNING, "Invalid removal 
offset: {0}", ex.offsetRequested()); // NOI18N
                             }
                         }
                     }
@@ -412,4 +411,4 @@ public class SearchComboBoxEditor implements ComboBoxEditor 
{
             return originalActionName;
         }
     };
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to