JDK-6366126 : List throws ArrayIndexOutOfBoundsException when pressing ENTER after removing all the items, Win32
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.2
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-12-21
  • Updated: 2018-01-30
  • Resolved: 2006-02-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b71Fixed
Related Reports
Relates :  
Relates :  
Description
I have a list with many items added to it. I am just removing all the items inside the itemStateChanged() method when the user selects an item. After this, I notice the following issues on Win32.

1. Focus still stays with the List even though all the items are removed.

2. Clicking the focus border shown on the top triggers an ItemEvent for List. 

3. Pressing 'ENTER' throws an ArrayIndexOutOfBoundsException.

Issue [3] is a regression in 1.4.2 or 1.4.1 since it is not reproducible on 1.4. This is noticed only on Win32 and works fine on XToolkit.

Here is the exception:
Exception in thread "AWT-EventQueue-0" 
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:434)
at java.awt.List.getItemImpl(List.java:292)
at java.awt.List.getItem(List.java:284)
at sun.awt.windows.WListPeer$1.run(WListPeer.java:176)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

I have attached a sample test. Execute the sample test. Click on any of the items in the list. Once all the items are removed, press ENTER. You would see the above exception on the console.

Comments
EVALUATION Look at the awt_List.cpp / WmNotify. We send events only if the list is non-empty: SendListMessage(LB_GETCURSEL) != LB_ERR works only for single-selection list. To fix it we should use LB_GETCOUNT. The similar issue exists on XAWT. Will create another issue to fix it separately.
18-01-2006

SUGGESTED FIX -bash-2.05b$ sccs diffs -C awt_List.cpp ------- awt_List.cpp ------- *** /tmp/sccs.BAyxqA 2006-01-19 15:42:30.000000000 +0300 --- awt_List.cpp 2006-01-19 15:23:07.000000000 +0300 *************** *** 661,667 **** if (notifyCode == LBN_SELCHANGE || notifyCode == LBN_DBLCLK) { /* Fixed an asserion failure when clicking on an empty List. */ int nCurrentSelection = GetCurrentSelection(); ! if (nCurrentSelection != LB_ERR) { if (notifyCode == LBN_SELCHANGE) { DoCallback("handleListChanged", "(I)V", nCurrentSelection); } --- 661,667 ---- if (notifyCode == LBN_SELCHANGE || notifyCode == LBN_DBLCLK) { /* Fixed an asserion failure when clicking on an empty List. */ int nCurrentSelection = GetCurrentSelection(); ! if (nCurrentSelection != LB_ERR && GetCount() > 0) { if (notifyCode == LBN_SELCHANGE) { DoCallback("handleListChanged", "(I)V", nCurrentSelection); }
18-01-2006

EVALUATION 1. Focus stays with a empty list with native windows application. So I suppose that it's not a bug. 2. Not a regression. Looks like we should filter LBN_SELCHANGE notification if the list is empty. 3. Regression since 1.4. It wasn't reproducable in 1.4 because this functionality was broken (ActionEvent wasn't triggered in this case). To fix it we should: - ignore LBN_DBLCLK if the list is empty - clarify our doc about exceptions: List.getItem() / ArrayIndexOutOfBoundsException (will comment it in CR#6247550 - will not be fixed here) Fix is very simple so should be fixed in mustang as regression.
16-01-2006