RFR: 6616245: NullPointerException when using JFileChooser with a custom FileView [v6]

Alexey Ivanov aivanov at openjdk.org
Mon Oct 10 18:47:57 UTC 2022


On Mon, 10 Oct 2022 16:52:48 GMT, Tejesh R <tr at openjdk.org> wrote:

>> When a custom `FileView` is used and folder traversal is restricted to a particular directory NPE occurs when user tries to traverse/select other folders except traversable folder. This is caused because when user selects folder other than traversable, the traversal is rejected and hence no file is selected as `currentDirectory` of `JFileChooser`. When user tries to access the restricted folder second time, previous selected file check is failing because of NPE since `getFileChooser().getCurrentDirectory();` is null. To fix the issue, NPE check is added.
>
> Tejesh R has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Updated based on review comments

Looks good to me now.

test/jdk/javax/swing/JFileChooser/FileViewNPETest.java line 82:

> 80:         passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 13, 40);
> 81:         jfc = new JFileChooser();
> 82:         String userHome = System.getProperty("user.home");

I prefer a blank line here to logically separate dealing with paths from creating the components. But it's a nit.

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

Marked as reviewed by aivanov (Reviewer).

PR: https://git.openjdk.org/jdk/pull/10485



More information about the client-libs-dev mailing list