JTree.updateUI() during TreeSelectionEvent.valueChanged() causes Null Pointer

Bug链接:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5089562

 

ERROR MESSAGES/STACK TRACES THAT OCCUR :

java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicTreeUI.completeEditing(BasicTreeUI.java:1
880)
        at javax.swing.plaf.basic.BasicTreeUI$TreeSelectionHandler.valueChanged(
BasicTreeUI.java:2496)
        at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTr
eeSelectionModel.java:629)
        at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTr
eeSelectionModel.java:1076)
        at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultT
reeSelectionModel.java:287)
        at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTr
eeSelectionModel.java:170)
        at javax.swing.JTree.setSelectionPath(JTree.java:1168)
        at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.jav
a:2192)
        at javax.swing.plaf.basic.BasicTreeUI$MouseHandler.handleSelection(Basic
TreeUI.java:2840)
        at javax.swing.plaf.basic.BasicTreeUI$MouseHandler.mousePressed(BasicTre
eUI.java:2801)
        at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:22
2)
        at java.awt.Component.processMouseEvent(Component.java:5097)
        at java.awt.Component.processEvent(Component.java:4897)
        at java.awt.Container.processEvent(Container.java:1569)
        at java.awt.Component.dispatchEventImpl(Component.java:3615)
        at java.awt.Container.dispatchEventImpl(Container.java:1627)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3195)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
        at java.awt.Container.dispatchEventImpl(Container.java:1613)
        at java.awt.Window.dispatchEventImpl(Window.java:1606)
        at java.awt.Component.dispatchEvent(Component.java:3477)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


重现代码
原因及解决: This behavior is not something that we can support.
Calling updateUI causes the tree's UI to be uninstalled and then a new one installed.
The developer is calling this method in the middle of events being dispatched
, some of which go to the UI. Because the events are already being dispatched,
they will still go to the uninstalled UI which no longer has reference to the tree
. The only way we could alleviate this problem would be to scatter numerous null checks
throughout all of the UI classes. Doing this would be nonsensical. Will not fix.
If the developer really wants this behavior,
they can wrap the call to updateUI in a SwingUtilities.invokeLater() .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值