diff --git a/src/share/classes/com/sun/servicetag/Installer.java b/src/share/classes/com/sun/servicetag/Installer.java index 0cda7afe3d6bdb1ae7eef7c6a6e98cfab27c7bc1..17555b913e94d9539937fa3a5c177b25d8d2a7c8 100644 --- a/src/share/classes/com/sun/servicetag/Installer.java +++ b/src/share/classes/com/sun/servicetag/Installer.java @@ -475,7 +475,7 @@ public class Installer { String filename = "/com/sun/servicetag/resources/javase_" + version + "_swordfish.properties"; - InputStream in = Installer.class.getClass().getResourceAsStream(filename); + InputStream in = Installer.class.getResourceAsStream(filename); if (in == null) { return null; } @@ -813,7 +813,7 @@ public class Installer { locale, String.valueOf(version)).toString(); try { - in = Installer.class.getClass().getResourceAsStream(resource + ".html"); + in = Installer.class.getResourceAsStream(resource + ".html"); if (in == null) { // if the resource file is missing if (isVerbose()) { @@ -825,34 +825,39 @@ public class Installer { System.out.println("Generating " + f + " from " + resource + ".html"); } - br = new BufferedReader(new InputStreamReader(in, "UTF-8")); - pw = new PrintWriter(f, "UTF-8"); - String line = null; - while ((line = br.readLine()) != null) { - String output = line; - if (line.contains(JDK_VERSION_KEY)) { - output = line.replace(JDK_VERSION_KEY, jdkVersion); - } else if (line.contains(JDK_HEADER_PNG_KEY)) { - output = line.replace(JDK_HEADER_PNG_KEY, headerImageSrc); - } else if (line.contains(REGISTRATION_URL_KEY)) { - output = line.replace(REGISTRATION_URL_KEY, registerURL); - } else if (line.contains(REGISTRATION_PAYLOAD_KEY)) { - output = line.replace(REGISTRATION_PAYLOAD_KEY, payload.toString()); + try { + br = new BufferedReader(new InputStreamReader(in, "UTF-8")); + pw = new PrintWriter(f, "UTF-8"); + String line = null; + while ((line = br.readLine()) != null) { + String output = line; + if (line.contains(JDK_VERSION_KEY)) { + output = line.replace(JDK_VERSION_KEY, jdkVersion); + } else if (line.contains(JDK_HEADER_PNG_KEY)) { + output = line.replace(JDK_HEADER_PNG_KEY, headerImageSrc); + } else if (line.contains(REGISTRATION_URL_KEY)) { + output = line.replace(REGISTRATION_URL_KEY, registerURL); + } else if (line.contains(REGISTRATION_PAYLOAD_KEY)) { + output = line.replace(REGISTRATION_PAYLOAD_KEY, payload.toString()); + } + pw.println(output); + } + f.setReadOnly(); + pw.flush(); + } finally { + // It's safe for this finally block to have two close statements + // consecutively as PrintWriter.close doesn't throw IOException. + if (pw != null) { + pw.close(); + } + if (br!= null) { + br.close(); } - pw.println(output); } - f.setReadOnly(); - pw.flush(); } finally { - if (pw != null) { - pw.close(); - } if (in != null) { in.close(); } - if (br!= null) { - br.close(); - } } } } diff --git a/src/share/classes/com/sun/servicetag/SunConnection.java b/src/share/classes/com/sun/servicetag/SunConnection.java index 8bcddbe971433fceed942a298f66f249e3d532c9..b05657866a5a9f12f191186d631212717c02e4d9 100644 --- a/src/share/classes/com/sun/servicetag/SunConnection.java +++ b/src/share/classes/com/sun/servicetag/SunConnection.java @@ -213,10 +213,16 @@ class SunConnection { con.setRequestProperty("Content-Type", "text/xml;charset=\"utf-8\""); con.connect(); - OutputStream out = con.getOutputStream(); - registration.storeToXML(out); - out.flush(); - out.close(); + OutputStream out = null; + try { + out = con.getOutputStream(); + registration.storeToXML(out); + out.flush(); + } finally { + if (out != null) { + out.close(); + } + } int returnCode = con.getResponseCode(); if (Util.isVerbose()) { diff --git a/src/share/classes/com/sun/servicetag/Util.java b/src/share/classes/com/sun/servicetag/Util.java index 9e32111a2fc826a935a6427918ea978962af8ba0..7d58d116e440209ca8a6dcd8172bd12734ce7cb4 100644 --- a/src/share/classes/com/sun/servicetag/Util.java +++ b/src/share/classes/com/sun/servicetag/Util.java @@ -140,11 +140,14 @@ class Util { } return e.getMessage(); } finally { - if (r != null) { - r.close(); - } - if (err != null) { - err.close(); + try { + if (r != null) { + r.close(); + } + } finally { + if (err != null) { + err.close(); + } } } } diff --git a/src/share/classes/com/sun/servicetag/WindowsSystemEnvironment.java b/src/share/classes/com/sun/servicetag/WindowsSystemEnvironment.java index 1fff0ea7df7f4b3e6f5ca83387629dc3c524c20d..aa9b83cdb6caec988925149886573d6099eac418 100644 --- a/src/share/classes/com/sun/servicetag/WindowsSystemEnvironment.java +++ b/src/share/classes/com/sun/servicetag/WindowsSystemEnvironment.java @@ -107,11 +107,17 @@ class WindowsSystemEnvironment extends SystemEnvironment { Process p = pb.start(); // need this for executing windows commands (at least // needed for executing wmic command) - BufferedWriter bw = new BufferedWriter( - new OutputStreamWriter(p.getOutputStream())); - bw.write(13); - bw.flush(); - bw.close(); + BufferedWriter bw = null; + try { + bw = new BufferedWriter( + new OutputStreamWriter(p.getOutputStream())); + bw.write(13); + bw.flush(); + } finally { + if (bw != null) { + bw.close(); + } + } p.waitFor(); if (p.exitValue() == 0) {