JDK-4980406 : PIT: JFileChooser hangs when navigating through the sub dirs
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P1
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,solaris_2.6,solaris_10,windows_98,windows_nt,windows_2000,windows_xp generic,solaris_2.6,solaris_10,windows_98,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86,sparc
  • Submitted: 2004-01-20
  • Updated: 2004-03-22
  • Resolved: 2004-02-28
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 b41Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
I am trying to print some print data to a file through the cross-platform print dialog. I am selecting 'PrintToFile' option in the print dialog and clicking 'OK'. A file dialog pops up. File dialog shows the current directory where the application is executed. I am opening a sub-directory. This sub-dir contains few files and the first file listed in the dir is selected by default. Now I am unable to navigate to any other directory nor change the file name. The file dialog just hangs there. I am unable to navigate to any other folder.

I have noticed the following when comparing the behavior with the previous build:

1. On the previous build this works fine.
2. On the PIT build, navigating to a sub-dir that has only files (not dir) makes the first file selected by default.
3. If the visited sub-dir contains another dir, that dir is shown as selected and file dialog does not hang.
4. Once the first file in the visited dir is selected by default, i am unable to change it to a diff file name. Even if I specify a new file name, it still shows an overwrite warning dialog saying the file already exists. So it does not take the new file name.

This is noticed only on the following PIT build, on all platforms:
java version "2d.pit-jcg-sparc-01-2004-01-18.tiger"
Java(TM) 2 Runtime Environment, Standard Edition (build 2d.pit-jcg-sparc-01-2004-01-18.tiger)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b33, mixed mode)

This is not reproducible on Tiger-b32a. I tested this on Win XP, Solaris 9(GNOME). 

I have attached a tar file. Untar it and you will find an app - PrintDlgApp.java. Execute the application. A print dialog will pop up. Click the 'PrintToFile' option. A file dialog will appear showing a dir 'output'. Open the 'output' dir. Inside the output dir, you would find 2 ps files out of which the first one will be shown as selected. Now try coming back to the parent folder by clicking the 'UP' icon or by choosing from the drop-down. If nothing happens and if you still remain in the same dir, the bug is reproduced.

-----------------------------------------------
###@###.### 2004-02-23

Same problem reported by a CAP member:

J2SE Version (please include all output from java -version flag):
  java version "1.5.0-beta2"
  Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b38)
  Java HotSpot(TM) Client VM (build 1.5.0-beta2-b38, mixed mode)

Does this problem occur on J2SE 1.3, 1.4 or 1.4.1?  Yes / No (pick one)
  No, works fine with build32c.

Operating System Configuration Information (be specific):
  Windows 2000 Professional SP2
  Redhat 9.0

Hardware Configuration Information (be specific):
  Custom built Athlon 600MHz, TNT2 AGP, 384MB

Bug Description:
  A JFileChooser with its FileSelectionMode set to DIRECTORIES_ONLY or 
  FILES_AND_DIRECTORIES will not respond to attempts to change directory 
  via the 'Look in:' drop-down or the 'Up one level' button.

  The behaviour seems to have changed at some point after b32c and is 
  evident in both b36 and b38.

Steps to Reproduce (be specific):
  Compile and run the following class, then attempt to select a different 
  directory using the 'Look in:' drop-down or the 'Up one level' button.


JFileChooserTest.java
=====================

import javax.swing.JFileChooser;

public class JFileChooserTest {

        public static void main(String[] args) {

                JFileChooser fc = new JFileChooser();
                fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                fc.showOpenDialog(null);
        }
}

--------------------------------------------------------

###@###.### 2004-03-08

Same problem reported by another CAP member:

J2SE Version (please include all output from java -version flag):
  java version "1.5.0-beta2"
  Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b40)
  Java HotSpot(TM) Client VM (build 1.5.0-beta2-b40, mixed mode)

Does this problem occur on J2SE 1.3.x or 1.4.x?   
  No
  
Operating System Configuration Information (be specific):
  Metal look and feel

Hardware Configuration Information (be specific):
  not hardware specific

Bug Description:
  The file which set with setSelectedFile() method
  does not displayed in the file name field
  display other file ( the 1st file in a directory )
  and can not change directory.

Steps to Reproduce (be specific):

run following program

//-------------- JFileChooserBug2.java ------------------------------
import javax.swing.*;
import java.io.*;

class JFileChooserBug2 {
   public static void main(String[] args) {
     JFileChooser jfc = new JFileChooser();

     File file = new File(
     "c:\\Program Files\\Java\\j2re1.5.0\\bin\\client\\Xusage.txt" );
     jfc.setSelectedFile( file );

     int ret = jfc.showOpenDialog( null );
     System.exit(0);
   }
}
//-------------------------------------------------------------------



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

EVALUATION ========================================================== This behavior started happening in 2D nightly build: java version "2d-jcg-sparc-01-2004-01-17.tiger" Java(TM) 2 Runtime Environment, Standard Edition (build 2d-jcg-sparc-01-2004-01-17.tiger) Java HotSpot(TM) Client VM (build 1.5.0-beta2-b33, mixed mode) The files that were brought over were Swing files so passing this to swing for further evaluation. ###@###.### 2004-01-20 ==================================== Name: keR10081 Date: 01/22/2004 We need to fix the broken functionality. I believe, however, that this is not P1 bug, since there is a workaround and nothing actually hangs. ###@###.### ====================================================================== Name: keR10081 Date: 01/30/2004 The reason of this bug is that we changed data that was not yet updated. Suggested fix removes redundant code that runs anyway, but now only for correct data. See suggested fix. ###@###.### ====================================================================== Name: keR10081 Date: 02/19/2004 We need to apply suggestef fix to correct the behaviour. ###@###.### ======================================================================
24-08-2004

WORK AROUND Name: keR10081 Date: 01/22/2004 Select first item (using mouse or arrow keys on keyboard) of the file list and then go to parent directory (using "One level up" button of the file chooser or backspace key of the keyboard). ======================================================================
24-08-2004

SUGGESTED FIX Name: keR10081 Date: 01/30/2004 *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/sun/swing/FilePane.java- Fri Jan 30 17:59:19 2004 --- FilePane.java Fri Jan 30 16:48:44 2004 *************** *** 1149,1155 **** applyEdit(); resetEditIndex(); - clearSelection(); ensureIndexIsVisible(0); File currentDirectory = fc.getCurrentDirectory(); if (currentDirectory != null) { --- 1149,1154 ---- ====================================================================== Name: keR10081 Date: 02/19/2004 *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/sun/swing/FilePane.java- Thu Feb 19 16:38:15 2004 --- FilePane.java Tue Feb 10 16:40:04 2004 *************** *** 413,418 **** --- 413,421 ---- updateListRowCount(list); } public void contentsChanged(ListDataEvent e) { + if (list != null && (!(((File)list.getModel().getElementAt(0)).equals(fileChooser.getCurrentDirectory())))) { + list.setSelectedIndex(0); + } listSelectionModel.clearSelection(); updateListRowCount(list); } *************** *** 1149,1155 **** applyEdit(); resetEditIndex(); - clearSelection(); ensureIndexIsVisible(0); File currentDirectory = fc.getCurrentDirectory(); if (currentDirectory != null) { --- 1152,1157 ---- *************** *** 1239,1246 **** } public void clearSelection() { ! if (listSelectionModel != null && list != null) { ! list.setSelectedIndex(0); listSelectionModel.clearSelection(); } } --- 1241,1247 ---- } public void clearSelection() { ! if (listSelectionModel != null) { listSelectionModel.clearSelection(); } } *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java- Thu Feb 19 16:38:04 2004 --- BasicDirectoryModel.java Tue Feb 10 16:45:18 2004 *************** *** 94,99 **** --- 94,100 ---- } if (loadThread != null) { loadThread.interrupt(); + loadThread.cancelRunnables(); } fetchID++; loadThread = new LoadFilesThread(currentDirectory, fetchID); *************** *** 253,258 **** --- 254,262 ---- } if (start >= 0 && end > start && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) { + if(isInterrupted()) { + return; + } invokeLater(new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid)); newFileCache = null; } *************** *** 269,274 **** --- 273,281 ---- } if (start >= 0 && end > start && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) { + if(isInterrupted()) { + return; + } invokeLater(new DoChangeContents(null, 0, new Vector(fileCache.subList(start, end)), start, fid)); newFileCache = null; *************** *** 275,285 **** } } if (newFileCache != null && !fileCache.equals(newFileCache)) { invokeLater(new DoChangeContents(newFileCache, 0, fileCache, 0, fid)); } - if (isInterrupted()) { - cancelRunnables(runnables); - } } --- 282,292 ---- } } if (newFileCache != null && !fileCache.equals(newFileCache)) { + if (isInterrupted()) { + cancelRunnables(runnables); + } invokeLater(new DoChangeContents(newFileCache, 0, fileCache, 0, fid)); } } *************** *** 288,295 **** ((DoChangeContents)runnables.elementAt(i)).cancel(); } } - } class DoChangeContents implements Runnable { private List addFiles; private List remFiles; --- 295,306 ---- ((DoChangeContents)runnables.elementAt(i)).cancel(); } } + public void cancelRunnables() { + cancelRunnables(runnables); + } + } + class DoChangeContents implements Runnable { private List addFiles; private List remFiles; *** /net/diablo/export2/swing/kve/tiger/webrev/src/share/classes/javax/swing/plaf/metal/MetalFileChooserUI.java- Thu Feb 19 16:38:08 2004 --- MetalFileChooserUI.java Wed Feb 11 15:55:19 2004 *************** *** 794,801 **** approveButton.setText(directoryOpenButtonText); approveButton.setToolTipText(directoryOpenButtonToolTipText); } else { ! approveButton.setText(getApproveButtonText(chooser)); ! approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); } } --- 794,803 ---- approveButton.setText(directoryOpenButtonText); approveButton.setToolTipText(directoryOpenButtonToolTipText); } else { ! if (approveButton != null) { ! approveButton.setText(getApproveButtonText(chooser)); ! approveButton.setToolTipText(getApproveButtonToolTipText(chooser)); ! } } } *************** *** 1109,1115 **** public void actionPerformed(ActionEvent e) { directoryComboBox.hidePopup(); File f = (File)directoryComboBox.getSelectedItem(); ! getFileChooser().setCurrentDirectory(f); } } --- 1111,1119 ---- public void actionPerformed(ActionEvent e) { directoryComboBox.hidePopup(); File f = (File)directoryComboBox.getSelectedItem(); ! if (!getFileChooser().getCurrentDirectory().equals(f)) { ! getFileChooser().setCurrentDirectory(f); ! } } } ======================================================================
24-08-2004