Skip to content

Commit b8e5b7b

Browse files
committed
use try-with-resources
1 parent c999f61 commit b8e5b7b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

visualvm/gotosource/src/org/graalvm/visualvm/gotosource/SourcesRoot.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,24 @@ private static SourcePathHandle getHandleInDirectory(Path directory, String sour
104104
}
105105

106106
private static SourcePathHandle getHandleInArchive(Path archive, String sourcePath, String[] subPaths, Charset encoding) throws Throwable {
107-
FileSystem archiveFileSystem = FileSystems.newFileSystem(archive, (ClassLoader)null);
108-
if (subPaths == null) {
109-
Path sourceFile = archiveFileSystem.getPath(sourcePath);
110-
return isFile(sourceFile) ? new SourcePathHandle(sourceFile, true, encoding) : null;
111-
} else {
112-
if (subPaths.length == 1 && MODULES_SUBPATH.equals(subPaths[0])) {
113-
Path path = archiveFileSystem.getRootDirectories().iterator().next();
114-
List<Path> subfolders = Files.walk(path, 1).filter(Files::isDirectory).collect(Collectors.toList());
115-
for (Path subfolder : subfolders) {
116-
Path sourceFile = subfolder.resolve(sourcePath);
107+
try (FileSystem archiveFileSystem = FileSystems.newFileSystem(archive, (ClassLoader)null)) {
108+
if (subPaths == null) {
109+
Path sourceFile = archiveFileSystem.getPath(sourcePath);
110+
return isFile(sourceFile) ? new SourcePathHandle(sourceFile, true, encoding) : null;
111+
} else {
112+
if (subPaths.length == 1 && MODULES_SUBPATH.equals(subPaths[0])) {
113+
Path path = archiveFileSystem.getRootDirectories().iterator().next();
114+
List<Path> subfolders = Files.walk(path, 1).filter(Files::isDirectory).collect(Collectors.toList());
115+
for (Path subfolder : subfolders) {
116+
Path sourceFile = subfolder.resolve(sourcePath);
117+
if (isFile(sourceFile)) return new SourcePathHandle(sourceFile, true, encoding);
118+
}
119+
} else for (String subPath : subPaths) {
120+
Path sourceFile = archiveFileSystem.getPath(subPath, sourcePath);
117121
if (isFile(sourceFile)) return new SourcePathHandle(sourceFile, true, encoding);
118122
}
119-
} else for (String subPath : subPaths) {
120-
Path sourceFile = archiveFileSystem.getPath(subPath, sourcePath);
121-
if (isFile(sourceFile)) return new SourcePathHandle(sourceFile, true, encoding);
123+
return null;
122124
}
123-
return null;
124125
}
125126
}
126127

0 commit comments

Comments
 (0)