<Swing Dev> RfR: JDK-8133897, IndexOutOfBounds exception being thrown
Walter Laan
WLaan at costengineering.eu
Fri Aug 21 07:43:52 UTC 2015
The patch just changes the AIOOB to a NPE elsewhere, for example to a method just above:
public Point getLocation() {
Rectangle r = getBounds();
return new Point(r.x, r.y);
}
Seems like the only way for the exception to happen is because removeTabAt() or setTitleAt() is called from a different thread than the EDT.
You could avoid the setTitleAt change, by using parent.pages.indexOf(this) although there might be a reason it is looked up by name everywhere.
It would still fail if the tab is removed from another thread, but it probably should fail in that case since Swing is not thread safe.
You could return an zero or negative sized rectangle, but that also might lead to problems elsewhere.
Thanks,
Walter
From: swing-dev [mailto:swing-dev-bounces at openjdk.java.net] On Behalf Of Pete Brunet
Sent: donderdag 20 augustus 2015 21:16
To: swing-dev at openjdk.java.net
Subject: Re: <Swing Dev> RfR: JDK-8133897, IndexOutOfBounds exception being thrown
Is this fix trivial enough to qualify for the noreg-trivial tag?
On 8/19/15 4:56 PM, Pete Brunet wrote:
On 8/19/15 4:50 PM, Pete Brunet wrote:
Please review this patch.
http://cr.openjdk.java.net/~ptbrunet/JDK-8133897/webrev.00/<http://cr.openjdk.java.net/%7Eptbrunet/JDK-8133897/webrev.00/>
The issue is that the application has a tab with a visible title but for some reason JTabbedPane's title field was "". This caused indexOfTab(title) to return -1 and then getTabBounds(parent, -1) raised ArrayIndexOutOfBoundsException.
public Rectangle getBounds() {
- return parent.getUI().getTabBounds(parent,
- parent.indexOfTab(title));
+ int i = parent.indexOfTab(title);
+ Rectangle r;
+ // Check for no title. Even though that's a bug in the app we should
+ // inhibit an ArrayIndexOutOfBoundsException from getTabBounds.
+ if (i == -1) {
+ r = null;
+ } else {
+ r = parent.getUI().getTabBounds(parent, i);
+ }
+ return r;
I suppose that could have been return (i == -1) ? null : parent.getUI().getTabBounds(parent, i);
}
Maybe someone more familiar with the code can see a bug related to why title is allowed to be "" when there is a visible title displayed in the tab. The bug I am working was raised during use of an app for which we do not have access so its source is not available.
Thanks, Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20150821/96159fad/attachment.html>
More information about the swing-dev
mailing list