JDK-6987233 : FileDialog.getDirectory() should add a trainling slash when GTK FileDialog is used
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2010-09-24
  • Updated: 2011-03-07
  • Resolved: 2011-03-07
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 b114Fixed
Related Reports
Relates :  
Description
The AWT FileDialog used to add the trailing slash to the directory name as returned by its getDirectory() method. This works fine on Windows, and on X11.

Recently the GTK FileDialog has been implemented on X11 which is activated if GTK libraries are present on the system. This native dialog seems to return the directory name w/o a trailing slash.

The presence of the trailing slahs isn't specified in the FileDialog.getDirectory() method. So, the correct code to use this method would be like:

   String filename = new File(dirpath, filename).getPath();

which would work always. However, there are applications that rely on the presence of the slash, and use an incorrect technique like this:

   String filename = new String(fd.getDirectory() + fd.getFile());

Due to the recent integration of the GTK file dialog this code starts to fail.

Even though such code is considered incorrect, and the presence of the slash isn't specified, we want to preserve behavioral compatibility in this case. Therefore, we need to add the slash manually in case of GTK file dialog.

Comments
SUGGESTED FIX --- old/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java 2010-09-27 18:38:04.000000000 +0400 +++ new/src/solaris/classes/sun/awt/X11/GtkFileDialogPeer.java 2010-09-27 18:38:04.000000000 +0400 @@ -64,7 +64,10 @@ accessor.setFile(fd, null); accessor.setFiles(fd, null, null); } else { - accessor.setDirectory(fd, directory); + // Fix 6987233: add the trailing slash if it's absent + accessor.setDirectory(fd, directory + + (directory.endsWith(File.separator) ? + "" : File.separator)); accessor.setFile(fd, filenames[0]); accessor.setFiles(fd, directory, filenames); }
27-09-2010

EVALUATION The trailing slash should be added in the sun.awt.X11.GtkFileDialogPeer.setFileInternal() method.
24-09-2010