On Tue, 10 Mar 2026 18:10:45 GMT, Kevin Rushforth <[email protected]> wrote:

>> modules/javafx.graphics/src/main/java/javafx/stage/FileChooser.java line 328:
>> 
>>> 326:      * @param ownerWindow the owner window of the displayed file dialog
>>> 327:      * @throws IllegalArgumentException if the initial directory does 
>>> not
>>> 328:      *      exist or is not a directory or is not accessible
>> 
>> I wonder if this is the right approach.  Yes, it currently works like that, 
>> but I think it's wrong!
>> What if the directory was deleted?  What if it was on a network share?
>> 
>> The right behavior should be to open the dialog using the current directory 
>> (ignoring the error), and let the user deal with it.
>
> That would be a noticeable behavior change. We could do what you suggest, but 
> then the application wouldn't be able to tell that's what happened. As it is, 
> the app can do what you suggest (catch the exception and set the dialog to 
> the current dir) or something else (maybe a default location for the app).
> 
> I wouldn't want to change it without more discussion.

I'd say the existing behavior is unexpected and wrong.  The use case where 
FileChooser is used to save or open file(s) should not require the application 
to invent additional code to handle transient directories, a quite possible 
scenario.

For instance, Swing `JFileChooser` ignores the non-existent currentDirectory 
and just uses the JVM's current one.


    public static void main(String[] args) throws Throwable {
        // enableLogging();
        //Application.launch(TreeView_Focus_8256142.class, args);
        EventQueue.invokeLater(AppTestLauncher::run);
    }
    
    private static void run() {
        JFrame f = new JFrame();
        f.setSize(100, 100);
        f.setVisible(true);

        JFileChooser c = new JFileChooser(new File("/blah"));
        c.showOpenDialog(f);
    }

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/2101#discussion_r2913732748

Reply via email to