powered by Jive Software

Swing and the Enhanched Debugger

After recieving a few exceptions from the enhanced debugger like this:

Exception in thread “Smack Writer Listener Processor” java.lang.ArrayIndexOutOfBoundsException: 2 >= 2

at java.util.Vector.elementAt(Vector.java:432)

at javax.swing.table.DefaultTableModel.justifyRows(DefaultTableModel.java:239)

at javax.swing.table.DefaultTableModel.insertRow(DefaultTableModel.java:348)

at javax.swing.table.DefaultTableModel.addRow(DefaultTableModel.java:323)

at javax.swing.table.DefaultTableModel.addRow(DefaultTableModel.java:334)

at org.jivesoftware.smackx.debugger.EnhancedDebugger.addSentPacketToTable(Enhanced Debugger.java:711)

at org.jivesoftware.smackx.debugger.EnhancedDebugger.access$100(EnhancedDebugger.j ava:51)

at org.jivesoftware.smackx.debugger.EnhancedDebugger$2.processPacket(EnhancedDebug ger.java:170)

at org.jivesoftware.smack.PacketWriter$ListenerWrapper.notifyListener(PacketWriter .java:321)

at org.jivesoftware.smack.PacketWriter.processListeners(PacketWriter.java:266)

at org.jivesoftware.smack.PacketWriter.access$100(PacketWriter.java:34)

at org.jivesoftware.smack.PacketWriter$2.run(PacketWriter.java:67)

/code

It was brought to my attention that none of the Swing code used by the debugger is called on the swing event thread. Anything that creates or modifies a swing object should be called from the swing event loop using SwingUtilities.InvokeLater, SwingWorker etc. I have a feeling this exception is popping up because of a race condition where a non-swing loop is modifying the Table model.