NullPointerException
I have a tool window with a JTextPane and JTextArea within JScrollPane components.
It all worked ok. But then I've added a feature that required to append the text in JTextPane multiple times in a quick succession and move the JScrollPane to the bottom each time. Moving scroll to the bottom looks more or less like this:
```
JScrollBar scrollBar = chatScroll.getVerticalScrollBar();
scrollBar.setValue(scrollBar.getMaximum());
```
Now, moving the scroll to the bottom was there before. The only thing that has changed was that I started doing that multiple times in quick succession (appending text JTextEditor and moving scroll at the bottom).
I started to get NullPointerException that makes the tool window completely inoperable (i.e. it just halts).
Here is the stack trace:
```
java.lang.NullPointerException
at java.desktop/javax.swing.text.BoxView.baselineRequirements(BoxView.java:1023)
at java.desktop/javax.swing.text.ParagraphView$Row.calculateMinorAxisRequirements(ParagraphView.java:949)
at java.desktop/javax.swing.text.BoxView.checkRequests(BoxView.java:936)
at java.desktop/javax.swing.text.BoxView.getMinimumSpan(BoxView.java:569)
at java.desktop/javax.swing.text.BoxView.calculateMajorAxisRequirements(BoxView.java:872)
at java.desktop/javax.swing.text.BoxView.checkRequests(BoxView.java:931)
at java.desktop/javax.swing.text.BoxView.getMinimumSpan(BoxView.java:569)
at java.desktop/javax.swing.text.BoxView.calculateMajorAxisRequirements(BoxView.java:872)
at java.desktop/javax.swing.text.BoxView.checkRequests(BoxView.java:931)
at java.desktop/javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:330)
at java.desktop/javax.swing.text.BoxView.layout(BoxView.java:710)
at java.desktop/javax.swing.text.BoxView.setSize(BoxView.java:398)
at java.desktop/javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1812)
at java.desktop/javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:942)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1683)
at java.desktop/javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1345)
at java.desktop/javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:795)
at java.desktop/java.awt.Container.layout(Container.java:1537)
at java.desktop/java.awt.Container.doLayout(Container.java:1526)
at java.desktop/java.awt.Container.validateTree(Container.java:1722)
at java.desktop/java.awt.Container.validate(Container.java:1657)
at java.desktop/javax.swing.RepaintManager$3.run(RepaintManager.java:748)
at java.desktop/javax.swing.RepaintManager$3.run(RepaintManager.java:746)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:745)
at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1900)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
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:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:891)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:760)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:447)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:818)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:446)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:488)
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)
```
At another time, I got slightly different stack trace:
```
java.lang.NullPointerException
at java.desktop/javax.swing.text.FlowView$FlowStrategy.layoutRow(FlowView.java:540)
at java.desktop/javax.swing.text.FlowView$FlowStrategy.layout(FlowView.java:498)
at java.desktop/javax.swing.text.FlowView.layout(FlowView.java:209)
at java.desktop/javax.swing.text.BoxView.setSize(BoxView.java:398)
at java.desktop/javax.swing.text.BoxView.updateChildSizes(BoxView.java:367)
at java.desktop/javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:349)
at java.desktop/javax.swing.text.BoxView.layout(BoxView.java:709)
at java.desktop/javax.swing.text.BoxView.setSize(BoxView.java:398)
at java.desktop/javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1812)
at java.desktop/javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:942)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1683)
at java.desktop/javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1345)
at java.desktop/javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:795)
at java.desktop/java.awt.Container.layout(Container.java:1537)
at java.desktop/java.awt.Container.doLayout(Container.java:1526)
at java.desktop/java.awt.Container.validateTree(Container.java:1722)
at java.desktop/java.awt.Container.validate(Container.java:1657)
at java.desktop/javax.swing.RepaintManager$3.run(RepaintManager.java:748)
at java.desktop/javax.swing.RepaintManager$3.run(RepaintManager.java:746)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:745)
at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1900)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
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:746)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:891)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:760)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:447)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:818)
at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:446)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:488)
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)
```
How can I approach this problem?
Please sign in to leave a comment.
Hi,
It is hard to tell what can be the reason with so little context. Are you appending the text and moving the scroll in EDT?