RSyntaxTextArea
RSyntaxTextArea copied to clipboard
NPE in PythonFoldParser
RSyntaxTextArea 3.1.1:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at org.fife.ui.rsyntaxtextarea.folding.PythonFoldParser.getFolds(PythonFoldParser.java:87)
at org.fife.ui.rsyntaxtextarea.folding.DefaultFoldManager.reparse(DefaultFoldManager.java:471)
at org.fife.ui.rsyntaxtextarea.folding.DefaultFoldManager$1.parse(DefaultFoldManager.java:503)
at org.fife.ui.rsyntaxtextarea.ParserManager.actionPerformed(ParserManager.java:163)
at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:317)
at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:249)
at java.desktop/java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:313)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
I can't provide detailed replication (yet; trying to isolate it) but it looks like IntelliJ wins this round 🤣
// IntelliJ can't tell, but it's not possible for currentFold to be
// null here
Haha fair enough!
I believe this bug is caused by this block:
// A code block without lines should just be removed
if (!foundBlock && currentFold != null && !currentFold.removeFromParent()) {
folds.remove(folds.size()-1);
}
which should probably be:
// A code block without lines should just be removed
if (!foundBlock && currentFold != null) {
Fold parent = currentFold.getParent();
if (!currentFold.removeFromParent()) {
folds.remove(folds.size() - 1);
}
currentFold = parent;
}
along with the defensive null check suggested or something similar. Unfortunately I can't reproduce this yet. I'd like to get a unit test in before pushing a change. Still working on this.
I can reliably reproduce with bottle.py; haven't yet narrowed it down to a smaller SSCCE:
https://bottlepy.org/docs/dev/tutorial.html#installation
SSCCE:
def abc2():
doSomething(
a,
)
pass
Seems to have to do with the mixed indentation on continuing lines. The trailing expression at a different indentation level is also necessary (to close the fold?). I'll probably check out a fix and file a PR soon.
Verified the NPE in a unit test. Suggested fix above isn't sufficient, trying some different things here: https://github.com/paul-griffith/RSyntaxTextArea/tree/python-fold-npe
Finally fixed by #508 (4a08790)!