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

FileChooser fails if initialDirectory does not exist

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux mydomain.at 4.8.13-100.fc23.x86_64 #1 SMP Fri Dec 9 14:51:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      FileChooser does not open

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      execute attached test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      FileChooser opens in default directory.
      I think the behaviour should be the same as if there was no initial directory or null set
      ACTUAL -
      FileChooser does not open

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in Application start method
      java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
      at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
      Caused by: java.lang.RuntimeException: Exception in Application start method
      at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
      at java.lang.Thread.run(Thread.java:745)
      Caused by: java.lang.IllegalArgumentException: Folder parameter must be a valid folder
      at com.sun.glass.ui.CommonDialogs.convertFolder(CommonDialogs.java:238)
      at com.sun.glass.ui.CommonDialogs.showFileChooser(CommonDialogs.java:190)
      at com.sun.javafx.tk.quantum.QuantumToolkit.showFileChooser(QuantumToolkit.java:1496)
      at javafx.stage.FileChooser.showDialog(FileChooser.java:416)
      at javafx.stage.FileChooser.showOpenDialog(FileChooser.java:350)
      at test.TestFileChooser.start(TestFileChooser.java:18)
      at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
      at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
      at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
      at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
      at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
      at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
      ... 1 more
      Exception running application test.TestFileChooser

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import java.io.File;

      import javafx.application.Application;
      import javafx.stage.FileChooser;
      import javafx.stage.Stage;

      public class TestFileChooser extends Application {
      public static void main(String[] args) {
      launch(args);
      }

      @Override
      public void start(Stage stage) {
      FileChooser f = new FileChooser();
      f.setInitialDirectory(new File("/nonexistingdirectory"));
      f.showOpenDialog(stage);
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      check manually if initial file exists:

      package test;

      import java.io.File;

      import javafx.application.Application;
      import javafx.stage.FileChooser;
      import javafx.stage.Stage;

      public class TestFileChooser extends Application {
      public static void main(String[] args) {
      launch(args);
      }

      @Override
      public void start(Stage stage) {
      FileChooser f = new FileChooser();
      File file = new File("/nonexistingdirectory");
      if (file.exists()) {
      f.setInitialDirectory(file);
      }
      f.showOpenDialog(stage);
      }
      }


            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: