Repository: commons-lang
Updated Branches:
  refs/heads/master dc53e49b4 -> 383bc8eef


LANG-1279: Update Java requirement from Java 6 to 7

use try with resources in SerializationUtils


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/f9cab271
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/f9cab271
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/f9cab271

Branch: refs/heads/master
Commit: f9cab271b3bc8c2fb6e2c51449ad3bc07e62e174
Parents: dc53e49
Author: pascalschumacher <pascalschumac...@gmx.net>
Authored: Sun Oct 23 22:30:00 2016 +0200
Committer: pascalschumacher <pascalschumac...@gmx.net>
Committed: Sun Oct 23 22:30:00 2016 +0200

----------------------------------------------------------------------
 .../commons/lang3/SerializationUtils.java       | 32 ++------------------
 1 file changed, 3 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/f9cab271/src/main/java/org/apache/commons/lang3/SerializationUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java 
b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
index f648695..b40063a 100644
--- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
@@ -136,22 +136,10 @@ public class SerializationUtils {
         if (outputStream == null) {
             throw new IllegalArgumentException("The OutputStream must not be 
null");
         }
-        ObjectOutputStream out = null;
-        try {
-            // stream closed in the finally
-            out = new ObjectOutputStream(outputStream);
+        try (ObjectOutputStream out = new ObjectOutputStream(outputStream)){
             out.writeObject(obj);
-
         } catch (final IOException ex) {
             throw new SerializationException(ex);
-        } finally {
-            try {
-                if (out != null) {
-                    out.close();
-                }
-            } catch (final IOException ex) { // NOPMD
-                // ignore close exception
-            }
         }
     }
 
@@ -205,26 +193,12 @@ public class SerializationUtils {
         if (inputStream == null) {
             throw new IllegalArgumentException("The InputStream must not be 
null");
         }
-        ObjectInputStream in = null;
-        try {
-            // stream closed in the finally
-            in = new ObjectInputStream(inputStream);
+        try (ObjectInputStream in = new ObjectInputStream(inputStream)) {
             @SuppressWarnings("unchecked")
             final T obj = (T) in.readObject();
             return obj;
-
-        } catch (final ClassNotFoundException ex) {
+        } catch (final ClassNotFoundException | IOException ex) {
             throw new SerializationException(ex);
-        } catch (final IOException ex) {
-            throw new SerializationException(ex);
-        } finally {
-            try {
-                if (in != null) {
-                    in.close();
-                }
-            } catch (final IOException ex) { // NOPMD
-                // ignore close exception
-            }
         }
     }
 

Reply via email to