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

[macos] Catalina macOS add additional period path with JFileChooser

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Mac OS Version 10.15.5
      Have tested on versions of java from OpenJDK 11 to 14, and IBM J9 java running on mac and all have similar issue.

      A DESCRIPTION OF THE PROBLEM :
      It seems the latest OS Catalina version Version 10.15.5 (latest as of date June28 2020) return incorrect absolute path by JFileChooser.
      I didn't recall this happening until the latest upgrade to Version 10.15.5

      What happen is the directory select by JFileChooser will return a extra period directory.
      eg Expected: /storage/hello/abc
      Return /storage/hello/./abc instead. There is always a extra /./ reference. It should return absolute path without the irrelevant period. I think this is critical as some application may parse and consider extra period directory as error.





      REGRESSION : Last worked in version 14.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test code that return directory select by JFileChooser

      For example selecting a directory
      /storage/hello/abc


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      /storage/hello/abc
      ACTUAL -
      /storage/hello/./abc

      ---------- BEGIN SOURCE ----------


      import javax.swing.*;
      import java.io.File;

      public class TestFileChooser {
        public static void main(String[] args) {

          final JFileChooser dirChooser = new JFileChooser();

          dirChooser.setCurrentDirectory(new java.io.File(".")); // Set initial directory
          dirChooser.setDialogTitle("Please select folder...");
          dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // Select directories only not file !!!

          int returnVal = dirChooser.showOpenDialog(new JFrame());

          if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = dirChooser.getSelectedFile();

            System.out.println("selected: " + file.getAbsolutePath());
          }
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
       Search and replace string "/./" with "/".
      However this is not practical as apparently the api is not returning "correct" path.

      FREQUENCY : always


        1. TestFileChooser.java
          0.7 kB
        2. 15ea-result-notreproduced.png
          15ea-result-notreproduced.png
          20 kB
        3. 15ea-result-reproduced.png
          15ea-result-reproduced.png
          21 kB
        4. Flash.png
          Flash.png
          24 kB
        5. SerialATA.PNG
          SerialATA.PNG
          76 kB

            serb Sergey Bylokhov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: