Could eliminate the duplication by always attempting `dir.mkdirs()`:
```
dir.mkdirs(); // don't care if this succeeds or fails
if (dir.isDirectory()) return dir;
throw ...
```