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

FileDialog return wrong directory name if path was entered manually

XMLWordPrintable

      FULL PRODUCT VERSION :
      $ java -version
      java version " 1.7.0_15 "
      Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
      Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Tested on Debian Squeeze with Kernel 2.6.32
      $ uname -a
      Linux lurkabove 2.6.32-matroxfb1000hz #3 SMP Fri Feb 17 20:41:15 CET 2012 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      The java.awt.FileDialog opens the GTK Filechooser in Java 7. That Filechooser allows to enter the full path to the file into the " Location " textfield (It even allows completion, so pressing the " tab " key completes the next segment of the path if possible).

      However, when doing this, Java correctly returns the selected _filename_, but ignores its real path and prepends it with the directory currently listed in the directory below the " Location " textfield. So instead of returning " /tmp/the_target_file " it returns " /currentdirectory/the_target_file " , if the content of " /currentdirectory " is displayed in the dialog.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case below from the Homedirectory (/home/username).

      The FileDialog displays the content of " /home/username " . When selecting a File in that listing and pressing the " Open " button, the output is:

      ----------------/-----------------------
      Directory: /home/username/
      Filename: selected_file.txt
      File[]: /home/username/selected_file.txt
      ----------------/-----------------------

      which is correct.

      If you do the same, but enter the full path to the file into the " Location " textbox to select " /tmp/the_other_file.txt " , the result is:
      ----------------/-----------------------
      Directory: /home/username/
      Filename: the_other_file.txt
      File[]: /home/username/the_other_file.txt
      ----------------/-----------------------

      which is obviously wrong.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Directory: /tmp/
      Filename: the_other_file.txt
      File[]: /tmp/the_other_file.txt
      ACTUAL -
      Directory: /home/username/
      Filename: the_other_file.txt
      File[]: /home/username/the_other_file.txt

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import java.awt.FileDialog;
      import java.awt.Frame;
      import java.io.File;

      public class FileDialogTest {

        public static void main(String[] args){
          FileDialog d= new FileDialog((Frame) null);
          d.setVisible(true);
          System.out.println( " Directory: " +d.getDirectory());
          System.out.println( " Filename: " +d.getFile());
          for (File f : d.getFiles()){
            System.out.println( " File[]: " +f.getPath());
          }
          d.dispose();
        }
      }
      ---------- END SOURCE ----------

            alexp Alexander Potochkin (Inactive)
            webbuggrp Webbug Group
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: