Ensure JarFile is always closed

dev/0.11
modmuss50 2020-04-22 18:22:22 +01:00
parent f7190b31c0
commit 26755cb82c
1 changed files with 29 additions and 31 deletions

View File

@ -83,7 +83,7 @@ public class ModProcessor {
} }
private static void handleNestedJars(File input, Project project, Configuration config, ResolvedArtifact artifact) throws IOException { private static void handleNestedJars(File input, Project project, Configuration config, ResolvedArtifact artifact) throws IOException {
JarFile jarFile = new JarFile(input); try (JarFile jarFile = new JarFile(input)) {
JarEntry modJsonEntry = jarFile.getJarEntry("fabric.mod.json"); JarEntry modJsonEntry = jarFile.getJarEntry("fabric.mod.json");
if (modJsonEntry == null) { if (modJsonEntry == null) {
@ -106,8 +106,7 @@ public class ModProcessor {
processNestedJar(jarFile, fileName, project, config, artifact); processNestedJar(jarFile, fileName, project, config, artifact);
} }
} }
}
jarFile.close();
} }
private static void processNestedJar(JarFile parentJar, String fileName, Project project, Configuration config, ResolvedArtifact artifact) throws IOException { private static void processNestedJar(JarFile parentJar, String fileName, Project project, Configuration config, ResolvedArtifact artifact) throws IOException {
@ -150,15 +149,15 @@ public class ModProcessor {
} }
private static void remapaccessWidener(File input, Project project) throws IOException { private static void remapaccessWidener(File input, Project project) throws IOException {
JarFile jarFile = new JarFile(input); String accessWidenerPath;
try (JarFile jarFile = new JarFile(input)) {
JarEntry modJsonEntry = jarFile.getJarEntry("fabric.mod.json"); JarEntry modJsonEntry = jarFile.getJarEntry("fabric.mod.json");
if (modJsonEntry == null) { if (modJsonEntry == null) {
return; return;
} }
String accessWidenerPath;
try (InputStream inputStream = jarFile.getInputStream(modJsonEntry)) { try (InputStream inputStream = jarFile.getInputStream(modJsonEntry)) {
JsonObject json = GSON.fromJson(new InputStreamReader(inputStream), JsonObject.class); JsonObject json = GSON.fromJson(new InputStreamReader(inputStream), JsonObject.class);
@ -168,8 +167,7 @@ public class ModProcessor {
accessWidenerPath = json.get("accessWidener").getAsString(); accessWidenerPath = json.get("accessWidener").getAsString();
} }
}
jarFile.close();
if (accessWidenerPath == null) { if (accessWidenerPath == null) {
return; return;