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