diff --git a/jdk/src/share/classes/java/io/BufferedReader.java b/jdk/src/share/classes/java/io/BufferedReader.java index 45a71f5cf1c..e8583e046f0 100644 --- a/jdk/src/share/classes/java/io/BufferedReader.java +++ b/jdk/src/share/classes/java/io/BufferedReader.java @@ -512,14 +512,11 @@ public class BufferedReader extends Reader { public void close() throws IOException { synchronized (lock) { - if (in != null) { - try { - in.close(); - } finally { - in = null; - cb = null; - } - } + if (in == null) + return; + in.close(); + in = null; + cb = null; } } } diff --git a/jdk/src/share/classes/java/io/BufferedWriter.java b/jdk/src/share/classes/java/io/BufferedWriter.java index fad7b44add4..4322683d367 100644 --- a/jdk/src/share/classes/java/io/BufferedWriter.java +++ b/jdk/src/share/classes/java/io/BufferedWriter.java @@ -255,16 +255,17 @@ public class BufferedWriter extends Writer { } } - @SuppressWarnings("try") public void close() throws IOException { synchronized (lock) { - if (out != null) { - try (Writer w = out) { - flushBuffer(); - } finally { - out = null; - cb = null; - } + if (out == null) { + return; + } + try { + flushBuffer(); + } finally { + out.close(); + out = null; + cb = null; } } } diff --git a/jdk/src/share/classes/java/io/FilterOutputStream.java b/jdk/src/share/classes/java/io/FilterOutputStream.java index b7e920b1753..97154443a81 100644 --- a/jdk/src/share/classes/java/io/FilterOutputStream.java +++ b/jdk/src/share/classes/java/io/FilterOutputStream.java @@ -152,10 +152,11 @@ class FilterOutputStream extends OutputStream { * @see java.io.FilterOutputStream#flush() * @see java.io.FilterOutputStream#out */ - @SuppressWarnings("try") public void close() throws IOException { - try (OutputStream ostream = out) { - flush(); + try { + flush(); + } catch (IOException ignored) { } + out.close(); } } diff --git a/jdk/src/share/classes/java/io/PushbackInputStream.java b/jdk/src/share/classes/java/io/PushbackInputStream.java index b6583f1dfb4..a0e240f1d84 100644 --- a/jdk/src/share/classes/java/io/PushbackInputStream.java +++ b/jdk/src/share/classes/java/io/PushbackInputStream.java @@ -374,13 +374,10 @@ class PushbackInputStream extends FilterInputStream { * @exception IOException if an I/O error occurs. */ public synchronized void close() throws IOException { - if (in != null) { - try { - in.close(); - } finally { - in = null; - buf = null; - } - } + if (in == null) + return; + in.close(); + in = null; + buf = null; } } diff --git a/jdk/src/share/classes/java/io/PushbackReader.java b/jdk/src/share/classes/java/io/PushbackReader.java index af44ee72fd3..3add8a5d3f7 100644 --- a/jdk/src/share/classes/java/io/PushbackReader.java +++ b/jdk/src/share/classes/java/io/PushbackReader.java @@ -245,11 +245,8 @@ public class PushbackReader extends FilterReader { * @exception IOException If an I/O error occurs */ public void close() throws IOException { - try { - super.close(); - } finally { - buf = null; - } + super.close(); + buf = null; } /** diff --git a/jdk/test/java/lang/ProcessBuilder/Basic.java b/jdk/test/java/lang/ProcessBuilder/Basic.java index e109a4e78bd..ebe65fb5bad 100644 --- a/jdk/test/java/lang/ProcessBuilder/Basic.java +++ b/jdk/test/java/lang/ProcessBuilder/Basic.java @@ -1762,9 +1762,9 @@ public class Basic { equal(p.exitValue(), 5); - try { p.getInputStream().close(); } catch (IOException ignore) { } - try {p.getErrorStream().close(); } catch (IOException ignore) { } - try { p.getOutputStream().close(); } catch (IOException ignore) { } + p.getInputStream().close(); + p.getErrorStream().close(); + p.getOutputStream().close(); InputStream[] streams = { p.getInputStream(), p.getErrorStream() }; for (final InputStream in : streams) {