Skip to content

Commit

Permalink
suppress another warning, de-nest some try/catches
Browse files Browse the repository at this point in the history
  • Loading branch information
pidster committed Feb 20, 2013
1 parent a28fea4 commit 02fde2b
Showing 1 changed file with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,24 +668,17 @@ public void handle(String deploymentID) {
}

private JsonObject loadModuleConfig(String modName, File modDir) {
// It's not clear to me whether the try-with-resources construct will
// close this correctly, the IDE complains about a resource leak. - Pid
try (Scanner scanner = new Scanner(new File(modDir, "mod.json")).useDelimiter("\\A")) {
String conf;
try {
conf = scanner.next();
} catch (NoSuchElementException e) {
throw new IllegalStateException("Module " + modName + " contains an empty mod.json file");
}
JsonObject json;
try {
json = new JsonObject(conf);
} catch (DecodeException e) {
throw new IllegalStateException("Module " + modName + " mod.json contains invalid json");
}
return json;
// Checked the byte code produced, .close() is called correctly, so the warning can be suppressed
try (@SuppressWarnings("resource") Scanner scanner = new Scanner(new File(modDir, "mod.json")).useDelimiter("\\A")) {
String conf = scanner.next();
return new JsonObject(conf);

} catch (FileNotFoundException e) {
throw new IllegalStateException("Module " + modName + " does not contain a mod.json file");
} catch (NoSuchElementException e) {
throw new IllegalStateException("Module " + modName + " contains an empty mod.json file");
} catch (DecodeException e) {
throw new IllegalStateException("Module " + modName + " mod.json contains invalid json");
}
}

Expand Down Expand Up @@ -923,8 +916,7 @@ private boolean unzipModule(final String modName, final String fileName, boolean
}

private boolean unzipModuleData(final File directory, final String fileName, boolean deleteZip) {
try (InputStream is = new BufferedInputStream(new FileInputStream(fileName))) {
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
try (InputStream is = new BufferedInputStream(new FileInputStream(fileName)); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is))) {
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (entry.isDirectory()) {
Expand Down

0 comments on commit 02fde2b

Please sign in to comment.