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

JFileChooser removes trailing spaces in the selected directory name

    Details

    • Subcomponent:
    • Resolved In Build:
      b124
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      1) java version "1.7.0_25"
      Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
      2)java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      1) Microsoft Windows [Wersja 6.1.7601]
      2) Linux pc-krb1-20-239.ericpol.int 2.6.32-279.11.1.el6.i686 #1 SMP Tue Oct 16 11:16:53 CDT 2012 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      If a directory, whose name ends with space characters, is selected in "javax.swing.JFileChooser" object, the call to "JFileChooser.getSelectedFile()" method returns "java.io.File" object representing a path to the selected directory but without any trailing spaces in its name.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Code:
      JFileChooser fc = new JFileChooser();
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      if (fc.showOpenDialog(data.getFrame()) == JFileChooser.APPROVE_OPTION)
      {
          File f = fc.getSelectedFile();
          boolean exists = f.exists();
      }
      Action:
      In shown JFileChooser choose the folder that contains spaces in the end of name (for example "Z:\123 " on Windows or "/local/123 " on linux) and observe by means of the debugger that "fc.getSelectedFile();" returns "java.io.File" object corresponding to "Z:\123" or "/local/123" paths without trailing spaces.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      f points on correct file ("Z:\123 " or "/local/123 ")
      and exists == true.
      ACTUAL -
      f points on file which name is without whitespaces ("Z:\123" or "/local/123")
      and exists == false.

      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alitvinov Anton Litvinov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: