JDK-4759922 : JFileChooser.rescanCurrentDirectory() crashes with an AIOBE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-10-08
  • Updated: 2003-12-15
  • Resolved: 2003-12-15
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.
Other
5.0 b32Fixed
Related Reports
Relates :  
Description

Name: rmT116609			Date: 10/08/2002


FULL PRODUCT VERSION :
java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

FULL OPERATING SYSTEM VERSION :
Windows NT Version 4.0
Windows 2000

A DESCRIPTION OF THE PROBLEM :
JFileChooser.rescanCurrentDirectory() crashes with an
ArrayIndexOutOfBoundsException if multiple selection is on
and the last selected file has been deleted (externally).

My example code calls rescanCurrentDirectory() with the
JFileChooser not visible, but the same error occurs if
it is visible.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run source code.
2. Select the last two files in any directory.
3. Externally delete the last file in the directory.
4. Cancel the dialog.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expect nothing (visible) to happen. Instead there is
an ArrayIndexOutOfBounds exception thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 18
	at java.util.Vector.get(Vector.java:713)
	at javax.swing.plaf.basic.BasicDirectoryModel.getElementAt
(BasicDirectoryModel.java:143)
	at javax.swing.JList.getSelectedValues(JList.java:1776)
	at javax.swing.plaf.metal.MetalFileChooserUI.setFileSelected
(MetalFileChooserUI.java:1200)
	at javax.swing.plaf.metal.MetalFileChooserUI$DelayedSelectionUpdater.run
(MetalFileChooserUI.java:904)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy
(EventDispatchThread.java:197)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:150)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;

    public class JFileChooserBug3 {
       public static void main(String args[]) {
         JFileChooser fc = new JFileChooser();
         fc.setMultiSelectionEnabled(true);
         fc.showOpenDialog(null);
         fc.rescanCurrentDirectory();
      }
   }


---------- END SOURCE ----------
(Review ID: 165528) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b32 tiger-beta
24-08-2004

EVALUATION Needs to be fixed for tiger. ###@###.### 2002-12-20 Name: keR10081 Date: 02/13/2003 The cause of problem lies in fact that BasicListUI's ListDataModel's contentsChanged doesn't update list selection model when list data model is updated, although intervalAdded and intervalRemoved do. So we get this AIOBE. This bug will probably be recategorized to JList. ###@###.### ====================================================================== Name: keR10081 Date: 02/21/2003 This bug is in fact caused by a bug in BasicListUI.ListDataHandler.contentsChanged(), where it doesn't update selection model on change in data model. So, this is a JList bug, not a JFileChooser one. ###@###.### ====================================================================== Name: keR10081 Date: 03/06/2003 As I've found out, this problem is the same as bug 4623505. So, we need to fix the latter bug to solve this problem. ###@###.### ====================================================================== Name: keR10081 Date: 09/16/2003 We need to clear selection on contents change. See suggested fix for details. ###@###.### ====================================================================== Name: keR10081 Date: 09/17/2003 After some source code rewriting, exceptions thrown look like these: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 10 at java.util.Vector.get(Vector.java:710) at javax.swing.plaf.basic.BasicDirectoryModel.getElementAt(BasicDirector yModel.java:143) at javax.swing.JList.getSelectedValues(JList.java:1781) at sun.swing.FilePane.setFileSelected(FilePane.java:1031) at sun.swing.FilePane$DelayedSelectionUpdater.run(FilePane.java:833) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:188) at java.awt.EventQueue.dispatchEvent(EventQueue.java:459) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh read.java:214) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre ad.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110) ###@###.### ======================================================================
24-08-2004

SUGGESTED FIX Name: keR10081 Date: 09/16/2003 *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/sun/swing/FilePane.java- Tue Sep 16 19:34:18 2003 --- FilePane.java Tue Sep 16 19:24:35 2003 *************** *** 405,410 **** --- 405,411 ---- updateListRowCount(list); } public void contentsChanged(ListDataEvent e) { + listSelectionModel.clearSelection(); updateListRowCount(list); } }); ======================================================================
24-08-2004