On Tue, 10 Mar 2026 22:07:53 GMT, John Hendrikx <[email protected]> wrote:

>> That's a fair point. Let's continue the discussion. I am not opposed to 
>> changing the behavior as long as we've thought through all the consequences.
>
> I think Andy is right here, we're dealing with IO. Whatever directory you set 
> can change at a moments notice (if it was correct to begin with). An 
> `IllegalArgumentException` should be for errors that can be 100% avoided and 
> so are always programming mistakes. However, in this case, even if I verify 
> that the `File` I set is a directory, and accessible, etc, this may not be 
> the case any more when the dialog is shown. It is not something you can blame 
> on the programmer when it inevitably fails.
> 
> The right approach then depends a bit on how crucial this initial directory 
> really is. If it must be there and it can't be anything else, then 
> `IOException` (which it was when thrown originally) would be appropriate to 
> indicate there may be a failure that cannot reasonably be always avoided 
> beforehand with better code. This is good because you can't miss it if you 
> forget to read docs.
> 
> However, in this case, being just a file chooser, it would also be 
> appropriate to fall back to some directory (perhaps selectable) or do 
> something like stripping paths from the given `File` until a directory is 
> found that does exist and is accessible.

Good point, though navigating up the file hierarchy might end up somewhere 
completely unrelated or where the user cannot access - "C:/" or "/" or "/mnt/"

It might be safer to fall back to the app's current directory (and the app can 
always implement alternative behavior by checking the initial dir before 
invoking the file chooser).

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

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

Reply via email to