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

Absolute path of symlink is null in JFileChooser

    XMLWordPrintable

Details

    • b10
    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Java version is 1.8.0_311, L&F used is Nimbus

      A DESCRIPTION OF THE PROBLEM :
      JFileChooser is created with selection mode DIRECTORIES_ONLY.
      When there is a symlink created by "mklink /D link target", this visually appears as a directory in JFileChooser but cannot by selected while normal directory can. By cannot be selected I don't mean it cannot be clicked by mouse or navigated to by arrow keys, but the PropertyChangeEvent for JFileChooser.SELECTED_FILE_CHANGED_PROPERTY reports the newValue to be null and also the Folder name: text field does not change to reflect the path of the selected symlink.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a regular directory in windows: mkdir c:\target
      2. Create a link targeting this directory: mklink /D c:\link c:\target
      3. In JFileChooser, navigate to c:\
      4. observe that when you click on target, the newValue of the property correctly reports "c:\target"
      5. click on link directory and see that the newValue reports null

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      newValue = "c:\link"
      ACTUAL -
      newValue = null

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;
      import java.awt.EventQueue;
      import java.beans.PropertyChangeEvent;
      import java.beans.PropertyChangeListener;
      import java.util.Arrays;

      import javax.swing.JFileChooser;
      import javax.swing.JFrame;
      import javax.swing.UIManager;
      import javax.swing.UnsupportedLookAndFeelException;
      import javax.swing.WindowConstants;

      public class FileChooserTest {

          public static void main(String[] args) {
              Arrays.stream(UIManager.getInstalledLookAndFeels()).filter(info -> "Nimbus".equals(info.getName())).findFirst().ifPresent(info -> {
                  try {
                      UIManager.setLookAndFeel(info.getClassName());
                  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                      //
                  }
              });

              JFrame frame = new JFrame("JFileChooser test");
              frame.setPreferredSize(new Dimension(600, 600));
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              JFileChooser jfc = new JFileChooser();
              jfc.setDialogType(JFileChooser.CUSTOM_DIALOG);
              jfc.setControlButtonsAreShown(false);
              jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
              jfc.addPropertyChangeListener(new PropertyChangeListener() {
                  public void propertyChange(PropertyChangeEvent evt) {
                      if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) {
                          System.out.println(String.format("Value changed: %s -> %s", evt.getOldValue(), evt.getNewValue()));
                      }
                  }
              });
              frame.add(jfc);
              frame.pack();
              EventQueue.invokeLater(() -> frame.setVisible(true));
          }
      }

      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              tr Tejesh R
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: