JDK-8223683 : JFileChooser sometimes calls native API which shows native modal dialogs
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u202
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-05-03
  • Updated: 2019-05-10
  • Resolved: 2019-05-10
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 10, Java 1.8.0_202

A DESCRIPTION OF THE PROBLEM :
Sometimes, for example when there is a broken link on the Desktop and you create a JFileChooser, a native dialog having the message something like "Windows cannot file target"" pops up.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a swing JFileChooser, sometimes even on the constructor it ends up calling native code and showing such modal native dialogs which are annoying to the end user. 
The code stack trace is something like this:

sun.awt.shell.Win32ShellFolder2.getLinkLocation(Native Method)
sun.awt.shell.Win32ShellFolder2.access$1400(Unknown Source)
sun.awt.shell.Win32ShellFolder2$11.call(Unknown Source)
sun.awt.shell.Win32ShellFolder2$11.call(Unknown Source)
java.util.concurrent.FutureTask.run(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
java.lang.Thread.run(Unknown Source)


Name: AWT-EventQueue-0
State: WAITING on java.util.concurrent.FutureTask@8abd246
Total blocked: 84  Total waited: 878

Stack trace: 
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.park(Unknown Source)
java.util.concurrent.FutureTask.awaitDone(Unknown Source)
java.util.concurrent.FutureTask.get(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Unknown Source)
sun.awt.shell.ShellFolder.invoke(Unknown Source)
sun.awt.shell.ShellFolder.invoke(Unknown Source)
sun.awt.shell.Win32ShellFolder2.getLinkLocation(Unknown Source)
sun.awt.shell.Win32ShellFolder2.getLinkLocation(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2.checkFile(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2.lambda$checkFiles$0(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2$$Lambda$85/580275385.test(Unknown Source)
java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)
java.util.Spliterators$ArraySpliterator.forEachRemaining(Unknown Source)
java.util.stream.AbstractPipeline.copyInto(Unknown Source)
java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
java.util.stream.AbstractPipeline.evaluate(Unknown Source)
java.util.stream.AbstractPipeline.evaluateToArrayNode(Unknown Source)
java.util.stream.ReferencePipeline.toArray(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2.checkFiles(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2.checkFiles(Unknown Source)
sun.awt.shell.Win32ShellFolder2.listFiles(Unknown Source)
sun.awt.shell.ShellFolder.listFiles(Unknown Source)
sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
sun.awt.shell.ShellFolder.get(Unknown Source)
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxModel.addItem(Unknown Source)
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$DirectoryComboBoxModel.access$800(Unknown Source)
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.doDirectoryChanged(Unknown Source)
com.sun.java.swing.plaf.windows.WindowsFileChooserUI.access$1100(Unknown Source)
com.sun.java.swing.plaf.windows.WindowsFileChooserUI$11.propertyChange(Unknown Source)
java.beans.PropertyChangeSupport.fire(Unknown Source)
java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
java.awt.Component.firePropertyChange(Unknown Source)
javax.swing.JFileChooser.setCurrentDirectory(Unknown Source)
javax.swing.JFileChooser.<init>(Unknown Source)
javax.swing.JFileChooser.<init>(Unknown Source)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Even if the JFileChooser ends up calling native code, it should avoid showing such native error dialogs. 
There is a client property called ""FileChooser.useShellFolder"" which can be set to "false" but in order to set it the JFileChooser needs to be created first. And sometimes the native error dialog is shown on the JFileChooser constuctor.

---------- BEGIN SOURCE ----------
Create a JFileChooser and use it to browse a folder which has a broken link inside it.
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Don't use the JFileChooser with a WindowsFileChooserUI

FREQUENCY : occasionally



Comments
This issue is reported with JDK 8u202, however this is now fixed in current version JDK 8u211 and 11.0.3 courtesy JDK-8213583, therefore closing this as a duplicate of same..
10-05-2019