Skip to content

SimpleChooserControl does not handle some non-existant paths #463

@VirtualTim

Description

@VirtualTim

SimpleChooserControl contains the following:

if (!new File(previousPath).isDirectory()) {
Path path = Paths.get(previousPath);
previousPath = path.getParent().toAbsolutePath().toString();
}
currentInitialDirectory = new File(previousPath);

There's two problems here:

  1. If the parent also doesn't exist (ie: C:\a\b) a NPE is thrown and nothing is displayed
  2. If that path is not valid, and does not contain a parent (ie: a), a NPE is thrown and nothing is displayed

I think this could be fixed by changing:

if (!new File(previousPath).isDirectory()) {
  Path path = Paths.get(previousPath);
  previousPath = path.getParent().toAbsolutePath().toString();

to

while (!new File(previousPath).isDirectory()) {
  Path path = Paths.get(previousPath);
  Path potentialParent = path.getParent();
  previousPath = potentialParent != null ? potentialParent.toAbsolutePath().toString() : null;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions