Skip to content

[NETBEANS-4620] NullPointerException - finding occurrences - #2325

Merged
neilcsmith-net merged 1 commit into
apache:masterfrom
junichi11:netbeans-4620
Aug 24, 2020
Merged

neilcsmith-net merged 1 commit into
apache:masterfrom
junichi11:netbeans-4620

Conversation

@junichi11

@junichi11 junichi11 commented Aug 23, 2020 •

Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/NETBEANS-4620
Probably https://issues.apache.org/jira/browse/NETBEANS-4623, too

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)

The other NPE:

java.lang.NullPointerException at java.desktop/javax.swing.text.JTextComponent.write(JTextComponent.java:1655) at
java.desktop/javax.swing.JEditorPane.getText(JEditorPane.java:1451) at
org.netbeans.modules.editor.search.SearchBar.showNumberOfMatches(SearchBar.java:1039) at
org.netbeans.modules.editor.search.SearchBar$13.caretUpdate(SearchBar.java:502) at 

JTextComponent.write is the following:

    public void write(Writer out) throws IOException {
        Document doc = getDocument();
        try {
            getUI().getEditorKit(this).write(out, doc, 0, doc.getLength());
        } catch (BadLocationException e) {
            throw new IOException(e.getMessage());
        }
    }

I've confirmed that editorPane.getUI().getEditorKit(editorPane) is null, when the new value is null. So we should be able to avoid NPE.

Steps to reproduce the problem in beta version

  • Select longer text than "Find" text field length
  • Run Find([Ctrl] + [F])
  • Click any place in editor (clear selection)
  • Run Find([Ctrl] + [F])
  • NPE occurs

CC: @DevCharly

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)
```
@junichi11 junichi11 added this to the 12.1 milestone Aug 23, 2020
@neilcsmith-net

Copy link
Copy Markdown
Member

Thanks @junichi11 So this is from fix for NB-4444, and a regression between 12.0 and 12.1? Agree we should merge for release, even if that delays us a few days. Need to work out what to do about commits that went in to master without being intended for 12.1.

cc @geertjanw

@junichi11

Copy link
Copy Markdown
Member Author

@neilcsmith-net

So this is from fix for NB-4444, and a regression between 12.0 and 12.1?

Yes, I think so. (#2188)

@neilcsmith-net

Copy link
Copy Markdown
Member

@lkishalmi not sure this should be backported for 12.0-u2 - #2188 is in 12.1 not 12.0.

@neilcsmith-net neilcsmith-net left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigating and fixing - merging now!

@neilcsmith-net
neilcsmith-net merged commit 412cee3 into apache:master Aug 24, 2020
@junichi11
junichi11 deleted the netbeans-4620 branch August 24, 2020 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants