Skip to content

Commit

Permalink
Java 7: try with resources
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoref committed Feb 21, 2019
1 parent 345b964 commit b79ec4f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
7 changes: 2 additions & 5 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -1770,12 +1770,9 @@ public String getLastErrorCheckUpdateCenters() {

protected String identifyPluginShortName(File t) {
try {
JarFile j = new JarFile(t);
try {
try (JarFile j = new JarFile(t)) {
String name = j.getManifest().getMainAttributes().getValue("Short-Name");
if (name!=null) return name;
} finally {
j.close();
if (name != null) return name;
}
} catch (IOException e) {
LOGGER.log(WARNING, "Failed to identify the short name from "+t,e);
Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/hudson/console/ConsoleNote.java
Expand Up @@ -192,18 +192,15 @@ private ByteArrayOutputStream encodeToBytes() throws IOException {

ByteArrayOutputStream buf2 = new ByteArrayOutputStream();

DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null));
try {
try (DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2, true, -1, null))) {
buf2.write(PREAMBLE);
if (JenkinsJVM.isJenkinsJVM()) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE
byte[] mac = MAC.mac(buf.toByteArray());
dos.writeInt(- mac.length); // negative to differentiate from older form
dos.writeInt(-mac.length); // negative to differentiate from older form
dos.write(mac);
}
dos.writeInt(buf.size());
buf.writeTo(dos);
} finally {
dos.close();
}
buf2.write(POSTAMBLE);
return buf2;
Expand Down
8 changes: 1 addition & 7 deletions core/src/main/java/hudson/tasks/Maven.java
Expand Up @@ -580,18 +580,12 @@ public String call() throws IOException {
if (jars != null) { // be defensive
for (File jar : jars) {
if (jar.getName().startsWith("maven-")) {
JarFile jf = null;
try {
jf = new JarFile(jar);
try (JarFile jf = new JarFile(jar)) {
Manifest manifest = jf.getManifest();
String version = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version != null) {
return version;
}
} finally {
if (jf != null) {
jf.close();
}
}
}
}
Expand Down

0 comments on commit b79ec4f

Please sign in to comment.