JDK-8261822 : JFileChooser does not work if Windows 10 desktop directory is missing
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u191,9,11,15,16,17,18,19
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2021-02-15
  • Updated: 2024-09-13
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
tbdUnresolved
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
If the user's desktop directory is missing in Windows 10, JFileChooser throws an exception and can not be used.

When the desktop directory is not present, the file chooser should recover gracefully and still be usable.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new user on Windows 10.
Use Windows Explorer to delete the new user's desktop directory (stay logged in else the desktop directory will be recreated).
Compile and run the code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect a usable file chooser without "Desktop" in the "Look in" list.
ACTUAL -
The file chooser does not pop up and these exceptions are displayed:

 Feb 15, 2021 6:00:52 PM sun.awt.shell.Win32ShellFolderManager2 getDesktop
 WARNING: Cannot access 'Desktop'
 java.io.IOException: Could not get shell folder ID list
 	at java.desktop/sun.awt.shell.Win32ShellFolder2.getFileSystemPath0(Native Method)
 	at java.desktop/sun.awt.shell.Win32ShellFolder2$7.call(Win32ShellFolder2.java:647)
 	at java.desktop/sun.awt.shell.Win32ShellFolder2$7.call(Win32ShellFolder2.java:645)
 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
 	at java.desktop/sun.awt.shell.Win32ShellFolderManager2$ComInvoker$1.run(Win32ShellFolderManager2.java:586)
 	at java.base/java.lang.Thread.run(Thread.java:832)
 
 Feb 15, 2021 6:00:52 PM sun.awt.shell.Win32ShellFolderManager2 getDesktop
 WARNING: Cannot access 'Desktop'
 java.io.IOException: Could not get shell folder ID list
 	at java.desktop/sun.awt.shell.Win32ShellFolder2.getFileSystemPath0(Native Method)
 	at java.desktop/sun.awt.shell.Win32ShellFolder2$7.call(Win32ShellFolder2.java:647)
 	at java.desktop/sun.awt.shell.Win32ShellFolder2$7.call(Win32ShellFolder2.java:645)
 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
 	at java.desktop/sun.awt.shell.Win32ShellFolderManager2$ComInvoker$1.run(Win32ShellFolderManager2.java:586)
 	at java.base/java.lang.Thread.run(Thread.java:832)
 
 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "sun.awt.shell.Win32ShellFolder2.getChildByPath(String)" because "desktop" is null
 	at java.desktop/sun.awt.shell.Win32ShellFolderManager2.getPersonal(Win32ShellFolderManager2.java:235)
 	at java.desktop/sun.awt.shell.Win32ShellFolderManager2.get(Win32ShellFolderManager2.java:282)
 	at java.desktop/sun.awt.shell.ShellFolder.get(ShellFolder.java:259)
 	at java.desktop/javax.swing.filechooser.FileSystemView.getDefaultDirectory(FileSystemView.java:449)
 	at java.desktop/javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:592)
 	at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:362)
 	at java.desktop/javax.swing.JFileChooser.<init>(JFileChooser.java:308)
 	at FileChooserTest.go(FileChooserTest.java:7)
 	at FileChooserTest.lambda$main$0(FileChooserTest.java:4)
 	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
 	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
 	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
 	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
 	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
 	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
 	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
 	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
 	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
 	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
 	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
 	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
 	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)




---------- BEGIN SOURCE ----------
import javax.swing.*; 
public class FileChooserTest { 
   public static void main(String args[]) {
      SwingUtilities.invokeLater(()->go());
   }
   public static void go() {
      final JFileChooser fc = new JFileChooser();
      fc.showOpenDialog(null);
   }
} 

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

FREQUENCY : always



Comments
Additional Information from submitter: ============================= Just to update this bug, we are still getting reports on this from at least Java 21.0.2, and since it is not marked as fixed I assume it is still there in Java 22. In our current Beta release we just alert the user that they need to fix the problem with the desktop directory, so we will not get these reports much longer and I thought I would let you know before this happens. It would be good if JFileChooser would just work with a deleted desktop directory - it should be an easy fix. Here is a recent stack dump from Java 21.0.2 on Windows 11. Cannot invoke "sun.awt.shell.Win32ShellFolder2.getIShellFolder()" because the return value of "sun.awt.shell.Win32ShellFolder2.getDesktop()" is null java.lang.NullPointerException: Cannot invoke "sun.awt.shell.Win32ShellFolder2.getIShellFolder()" because the return value of "sun.awt.shell.Win32ShellFolder2.getDesktop()" is null at java.desktop/sun.awt.shell.Win32ShellFolder2$1.call(Win32ShellFolder2.java:297) at java.desktop/sun.awt.shell.Win32ShellFolder2$1.call(Win32ShellFolder2.java:292) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) at java.desktop/sun.awt.shell.Win32ShellFolderManager2$ComInvoker$1.run(Win32ShellFolderManager2.java:599) at java.base/java.lang.Thread.run(Thread.java:1583)
13-09-2024

Additional Information from submitter: ============================= The exceptions in the report are from OpenJDK 15.0.2. I also tested with OpenJDK 15.0.1 and found the same. Occasionally we have users with some sort of system directory problem - missing, inaccessible, etc. so we do encounter this and similar problems in practice.
17-02-2021

Mail to submitter: ============ Could you please confirm the version of JDK, in which issue is observed?
16-02-2021