JDK-8050212 : FileDialog return wrong directory name if path was entered manually
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u15
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • Submitted: 2013-03-16
  • Updated: 2014-07-24
  • Resolved: 2014-07-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7-poolResolved
Related Reports
Duplicate :  
Description
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 ----------
Comments
It is fixed in jdk9 by JDK-8040007
15-07-2014

try jdk9
14-07-2014