Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6532180

JFileChooser throws exception after changing file filter at sorted files

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      'Native' Filechooser will freeze if you try to change filefilter on a sorted fileview.
      You've to enable detailed view for that.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the code
      2. Enable detailed view of the file chooser.
      3. Change to a directory with txt files.
      4. Change "Files of type" to "All Files"
      5. Sort files (e.g.: by date).
      6. Change the "Files of type" to "*.txt" <- Exception thrown

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Of course the correct files should be displayed.
      ACTUAL -
      Depends on the shown file(s).
      Sometimes only the first result is shown (changing to another file fiter (e.g.: jpg)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception occurred during event dispatching:
      java.lang.ArrayIndexOutOfBoundsException: 15
              at javax.swing.DefaultRowSorter.convertRowIndexToModel(Unknown Source)
              at sun.swing.FilePane$SortableListModel.getElementAt(Unknown Source)
              at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
              at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
              at javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.setAnchorSelectionIndex(Unknown Source)
              at javax.swing.JTable.clearSelectionAndLeadAnchor(Unknown Source)
              at javax.swing.JTable.tableChanged(Unknown Source)
              at sun.swing.FilePane$5.tableChanged(Unknown Source)
              at javax.swing.table.AbstractTableModel.fireTableChanged(Unknown Source)

              at javax.swing.table.AbstractTableModel.fireTableStructureChanged(Unknown Source)
              at sun.swing.FilePane$DetailsTableModel.updateColumnInfo(Unknown Source)

              at sun.swing.FilePane$DetailsTableModel.contentsChanged(Unknown Source)
              at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
              at javax.swing.plaf.basic.BasicDirectoryModel.fireContentsChanged(Unknown Source)
              at javax.swing.plaf.basic.BasicDirectoryModel$DoChangeContents.run(Unknown Source)
              at java.awt.event.InvocationEvent.dispatch(Unknown Source)
              at java.awt.EventQueue.dispatchEvent(Unknown Source)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.Dialog$1.run(Unknown Source)
              at java.awt.event.InvocationEvent.dispatch(Unknown Source)
              at java.awt.EventQueue.dispatchEvent(Unknown Source)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
              at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
              at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
              at java.awt.EventDispatchThread.run(Unknown Source)
      Exception occurred during event dispatching:
      java.lang.ArrayIndexOutOfBoundsException: 15
              at javax.swing.DefaultRowSorter.convertRowIndexToModel(Unknown Source)
              at sun.swing.FilePane$SortableListModel.getElementAt(Unknown Source)
              at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
              at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
              at javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
              at javax.swing.DefaultListSelectionModel.setAnchorSelectionIndex(Unknown
       Source)
              at sun.swing.FilePane.clearSelection(Unknown Source)
              at sun.swing.FilePane.setFileSelected(Unknown Source)
              at sun.swing.FilePane$DelayedSelectionUpdater.run(Unknown Source)
              at java.awt.event.InvocationEvent.dispatch(Unknown Source)
              at java.awt.EventQueue.dispatchEvent(Unknown Source)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.Dialog$1.run(Unknown Source)
              at java.awt.event.InvocationEvent.dispatch(Unknown Source)
              at java.awt.EventQueue.dispatchEvent(Unknown Source)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
              at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
              at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
              at java.awt.EventDispatchThread.run(Unknown Source)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /*
       * Main.java
       *
       * Created on 07 March 2007, 11:18
       *
       * To change this template, choose Tools | Template Manager
       * and open the template in the editor.
       */

      package testbug;

      import java.awt.HeadlessException;
      import java.io.File;
      import javax.swing.filechooser.FileFilter;
      import javax.swing.JFileChooser;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;

      /**
       *
       * @author hartmann-v
       */
      public class Main {
        
        /** Creates a new instance of Main */
        public Main() {
        }
        
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
          try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            JFileChooser fileChooser = new JFileChooser();
            FileFilter filter = new FileFilter() {
              public boolean accept(File pathname) {
                if (pathname.isDirectory())
                  return true;
                return pathname.getName().endsWith("txt");
              }
              public String getDescription() {
                return "change me after sorting files";
              }
            };
            fileChooser.addChoosableFileFilter(filter);
            fileChooser.setFileFilter(filter);
            fileChooser.showOpenDialog(null);
          } catch (HeadlessException ex) {
            ex.printStackTrace();
          } catch (InstantiationException ex) {
            ex.printStackTrace();
          } catch (IllegalAccessException ex) {
            ex.printStackTrace();
          } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
          } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
          }
        }
        
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: