darklaf icon indicating copy to clipboard operation
darklaf copied to clipboard

DarkTableHeaderUI.paintDraggedArea(...) doesn't handle scenario where the column is not found

Open josple opened this issue 10 months ago • 1 comments

Describe the bug com.github.weisj.darklaf.ui.table.header.DarkTableHeaderUI.paintDraggedArea(Graphics2D, boolean, int, int, Color, TableColumn) makes a call to com.github.weisj.darklaf.ui.table.header.DarkTableHeaderUI.viewIndexForColumn(TableColumn) which can sometimes return -1 if the dragged column cannot be found.

In this scenario an exception is ultimately thrown:

java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10
	at java.base/java.util.Vector.elementData(Vector.java:731)
	at java.base/java.util.Vector.elementAt(Vector.java:469)
	at java.desktop/javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:295)
	at com.github.weisj.darklaf.ui.table.header.DarkTableHeaderUI.getHeaderCellRenderer(DarkTableHeaderUI.java:319)
	at com.github.weisj.darklaf.ui.table.header.DarkTableHeaderUI.paintCell(DarkTableHeaderUI.java:273)
	at com.github.weisj.darklaf.ui.table.header.DarkTableHeaderUI.paintDraggedArea(DarkTableHeaderUI.java:256)
	at com.github.weisj.darklaf.ui.table.header.DarkTableHeaderUI.paint(DarkTableHeaderUI.java:141)

Potentially having a -1 check and returning early would be a quick fix to avoid the exception (although I appreciate this may be masking a general underlying problem of why we cannot find the column). For context, we have only seen this once out of 10,000s of runs and I cant understand why a JTable is even in play in our scenario, and I am unable to reproduce.

josple avatar Feb 20 '25 10:02 josple

I don't think finding the root cause of the issue will be easy. The code builds on top of BasicLookAndFeel which is very convoluted and I don't fully have an overview myself what is happening there (maybe once I did but now at least I don't anymore). A simple range checks is good enough for now.

weisJ avatar Feb 21 '25 14:02 weisJ