Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8191957

JFileChooser shows empty name for external drives shown under Desktop

XMLWordPrintable

    • b08
    • x86_64
    • windows_10

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.16299.64]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      You need an external drive attached to the system so under 'Desktop' it shows the external drive. Open 'Windows Explorer', on the left hand side, you will see external hard drives attached. Note the 'Desktop' is the root of FileSystemView, not the 'Desktop' under 'This PC' directory.


      A DESCRIPTION OF THE PROBLEM :
      In JFileChooser, navigate to the root directory, 'Desktop', you will see those external hard drives shown as empty names.

      The root cause is this function:
      http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/65464a307408/src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java#l447

      In Win32ShellFolderManager2.isFileSystemRoot(File dir), It checks if the directory is the child of 'DRIVES' (i.e. 'This PC', a.k.a. 'My Computer' in earlier versions) therefore the external drives under 'This PC' works, but not the ones under 'Desktop'. This leads to isFileSystemRoot == false for those external drives.

      Then in FileSystemView.getSystemDisplayName(): http://hg.openjdk.java.net/jdk9/jdk9/jdk/file/65464a307408/src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java#l191, the condition failed: useSystemExtensionHiding || !isFileSystem(f) || isFileSystemRoot(f).

      This function should check if the parent is 'Desktop' as well.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Download and run the official FileChooseDemo at https://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html#FileChooserDemo

      Click 'Open a File', and then click the drop down near 'Look in', and select 'Desktop' at top-level. Note: DON'T select the 'Desktop' under 'This PC' (a.k.a. 'My Computer' in earlier versions of Windows).




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Labels are shown to the right of the icons for those external drives.
      ACTUAL -
      There is no text along side the icon.
      https://ibb.co/nuvOcm

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      The official JFileChooserDemo at https://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html#FileChooserDemo
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the property "FileChooser.useSystemExtensionHiding" to true.

      UIManager.put("FileChooser.useSystemExtensionHiding", true);

            pbansal Pankaj Bansal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: