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

JFileChooser with Metal L&F doesn't show non-canonical UNC path in - Look in

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b05
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, 64 Bit

      OpenJDK 17.0.1

      A DESCRIPTION OF THE PROBLEM :
      When opening a JFileChooser in a non-canonical UNC path (e.g. \\pc-name\dir\..), the "Look in" Combobox at the top for quickly changing directory is empty, even though the main content correctly lists the files contained in the directory.

      It only happens with MetalLookAndFeel. When Changing to WindowsLookAndFeel, everything works as expected.

      Comparing the two, MetalFileChooserUI.addItem(File directory) calls ShellFolder.getNormalizedFile(directory), whereas WindowsFileChooserUI.addItem(File director) just calls directory.getCanonicalPath().

      ShellFolder.getNormalizedFile checks if the path is already canonical, and returns it unchanged if so. Otherwise, it converts the file tu a normalized URI and back to a File again, supposedly to better handle symbolic links, according to a comment. But in this conversion, one of the two leading backslashes is lost. For example, when passing "\\pc-name\dir\..", the result is "\pc-name", but it should be "\\pc-name".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the give Java program, passing a non-canonical UNC path, e.g. "\\pc-name\dir\..".

      You can comment/uncomment the lines that set a LookAndFeel to test both and compare.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The file chooser should show the given directory in the "Look in" component, and list its content.
      ACTUAL -
      With the MetalLookAndFeel, the "Look in" component remains empty, but the directory content is listed correctly.

      ---------- BEGIN SOURCE ----------
      package swing;

      import javax.swing.JFileChooser;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;

      public class UNCFileChooserIssue {

          public static void main(String[] args) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
              if (args.length == 0) {
                  System.out.println("Usage: java UNCFileCHooserIssue <path>");
                  System.exit(1);
              }
              // Comment/uncomment to change LookAndFeel
              UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
              //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              new JFileChooser(args[0]).showOpenDialog(null);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      The workaround is to manually ensure that only canonical paths are given to JFileChooser, such that the "lossy" conversion doesn't happen.

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: