Qoracoin / Qora

Public GIT for the Qora cryptocurrency project.
http://qora.org
Other
43 stars 24 forks source link

NPE in BlocksTableModel.getValueAt() during JSwing repaint #71

Open catbref opened 6 years ago

catbref commented 6 years ago
2017-12-04 14:34:58 ERROR DBMap:119 - 
java.lang.ArrayIndexOutOfBoundsException
2017-12-04 14:34:58 ERROR BlocksTableModel:109 - 
java.lang.NullPointerException
        at gui.models.BlocksTableModel.getValueAt(BlocksTableModel.java:82)
        at javax.swing.JTable.getValueAt(Unknown Source)
        at javax.swing.JTable.prepareRenderer(Unknown Source)
        at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
        at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
        at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
        at javax.swing.plaf.ComponentUI.update(Unknown Source)
        at javax.swing.JComponent.paintComponent(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JViewport.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintChildren(Unknown Source)
        at javax.swing.JComponent.paint(Unknown Source)
        at javax.swing.JComponent.paintToOffscreen(Unknown Source)
        at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
        at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
        at javax.swing.RepaintManager.paint(Unknown Source)
        at javax.swing.JComponent._paintImmediately(Unknown Source)
        at javax.swing.JComponent.paintImmediately(Unknown Source)
        at javax.swing.RepaintManager$4.run(Unknown Source)
        at javax.swing.RepaintManager$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
        at javax.swing.RepaintManager.access$1200(Unknown Source)
        at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

Note that the DBMap frame may/may not be relevant!

catbref commented 6 years ago

There are several similar errors but looks like the common root is BlocksTableModel.java line 76: Block block = blocks.get(row).getB(); where block is assigned null.

Both blocks.get(row) and then .getB() don't throw so there is an entry in blocks at index row but why is it null?

ghost commented 6 years ago

Just tried to reproduce this bug but wasn't able to. Is there any more information about the use case that leads to this exception?

ghost commented 6 years ago

I didn't follow every single control path yet and I'm not sure if this can even occur, so please bear with me, given my limited understanding of the code. Anyhow, I guess it might be a threading problem:

As far as I saw, SortableList is not thread safe (or I didn't grasp the concept :) ).

A list of this type is returned from BlocksTableModel.getSortableList() and sorted in QoraRowSorter (l.45): this.model.getSortableList().sort(this.indexes.get(column), order.equals(SortOrder.DESCENDING));

If another thread calls BlocksTableModel.getValueAt(..) at the same time the list is sorted, this could lead to almost any result, including a null value.

A similar problem could be the cause for issue #70.

Possible or complete nonsense?