Skip to content

Commit 660bc05

Browse files
committed
fix: ensure stream close
1 parent f5768f2 commit 660bc05

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • HMCLCore/src/main/java/org/jackhuang/hmcl/game

HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ public World(Path file) throws IOException {
8888
root = fs.getPath("/");
8989
fileName = FileUtils.getName(this.file);
9090
} else {
91-
List<Path> files = Files.list(fs.getPath("/")).toList();
92-
if (files.size() != 1 || !Files.isDirectory(files.get(0))) {
93-
throw new IOException("Not a valid world zip file");
94-
}
91+
try (Stream<Path> filesStream = Files.list(fs.getPath("/"))) {
92+
List<Path> files = filesStream.toList();
93+
if (files.size() != 1 || !Files.isDirectory(files.get(0))) {
94+
throw new IOException("Not a valid world zip file");
95+
}
9596

96-
root = files.get(0);
97-
fileName = FileUtils.getName(root);
97+
root = files.get(0);
98+
fileName = FileUtils.getName(root);
99+
}
98100
}
99101

100102
Path levelDat = root.resolve("level.dat");

0 commit comments

Comments
 (0)