Skip to content

Commit

Permalink
More robustness fixes for curr dir (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed May 16, 2021
1 parent 72c8731 commit 701c263
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/main/java/nonapi/io/github/classgraph/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,45 @@ public static String currDirPath() {
if (currDirPathStr != null) {
try {
path = Paths.get(currDirPathStr);
} catch (final InvalidPathException e2) {
if (!path.toFile().canRead()) {
path = null;
}
} catch (final InvalidPathException | UnsupportedOperationException | SecurityException e) {
// Fall through
}
} else {
}
if (path == null) {
// user.dir should probably always be set. But just in case it is not, try reading the
// actual current directory at the time ClassGraph is first invoked.
try {
path = Paths.get("");
} catch (final InvalidPathException e1) {
try {
path = Paths.get(".");
} catch (final InvalidPathException e2) {
// Fall through
if (!path.toFile().canRead()) {
path = null;
}
} catch (final InvalidPathException | UnsupportedOperationException | SecurityException e) {
// Fall through
}
}
if (path == null) {
try {
path = Paths.get(".");
if (!path.toFile().canRead()) {
path = null;
}
} catch (final InvalidPathException | UnsupportedOperationException | SecurityException e) {
// Fall through
}
}
// Try normalizing path
if (path != null) {
currDirPathStr = null;
try {
currDirPathStr = path.toRealPath(LinkOption.NOFOLLOW_LINKS).toString();
} catch (IOError | SecurityException | IOException e) {
// Fall through
}
} else {
currDirPathStr = "";
}
// Normalize current directory the same way all other paths are normalized in ClassGraph,
// for consistency
Expand Down

0 comments on commit 701c263

Please sign in to comment.