JDK-6317789 : REGRESSION: JFileChooser() hangs when encountering a shortcut to the desktop
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-08-30
  • Updated: 2011-02-16
  • Resolved: 2006-05-10
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 b84Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP  Service Pack 2 (also happens /w service pack 1)

EXTRA RELEVANT SYSTEM CONFIGURATION :
Not hardware specific

A DESCRIPTION OF THE PROBLEM :
Java hangs completely when JFileChooser() is called when a shortcut to the desktop is present on the desktop of Windows XP.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

In windows XP right-click on the desktop,  select  "new" from the popup menu then select "shortcut:". In the popup-dialog select "browse", then select the topmost item in the tree "desktop". Select ok. This will create a shortcut to the desktop on the desktop. I have used a shortcut like this for quick access to my desktop icons from a popup window (works well when assigned a hotkey).

Next, create a simple java program that simply calls the default constructor of JFileChooser  - ie:


 public class Test {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFileChooser fileChooser = new JFileChooser();
            };
        });
    }
}

When run with JDK 5.0 this program will hang. However, if you delete the desktop link the program runs to completion. If you run this program with JDK 1.4 it works fine - even with the desktop  link.

As a final note, the bug is not present if you set the "useShellFolder" property to false, ie:

                JFileChooser fileChooser = new JFileChooser() {
                    public void updateUI() {
                        putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
                        super.updateUI();
                    }
                };



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I did not expect java to hang.
ACTUAL -
Java hung and the program had to be terminated by task manager.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Test {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                // java will hang here if a particular shortcut is present on the desktop
                JFileChooser fileChooser = new JFileChooser();
            };
        });
    }
}

See steps above for creating the shortcut on the desktop.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Delete the desktop link (see steps for recreating) or add

    putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);

to all JFileChooserClasses.

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

Comments
EVALUATION The cause is that native Win32ShellFolder2.copyFirstPIDLEntry() can return 0 if the ID list is empty, and this is the case for a shortcut to the Desktop created on the Desktop itself. This situation was not handled in Win32ShellFolder2.createShellFolderFromRelativePIDL(). It didn't appear earlier because JFileChooser didn't supported shortcuts. Since ###@###.### added the support for shortcuts as the fix for 4356160, it became possible to do that trick with shortcut looping.
23-03-2006

SUGGESTED FIX In Win32ShellFolder2.createShellFolderFromRelativePIDL(), break the cycle if native Win32ShellFolder2.copyFirstPIDLEntry() returns 0 (see the implementation of the latter, it has a branch that returns 0 if the ID list is empty).
23-03-2006

EVALUATION Need to verify that bug is present in Mustang beta.
08-11-2005