commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [lang] Use try-with-resources.
Date Sun, 23 Oct 2016 17:59:18 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master eb2b89efb -> 151f2cd3d


Use try-with-resources.

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

Branch: refs/heads/master
Commit: 151f2cd3d80c006f4ec228cdf610c3a35feb195d
Parents: eb2b89e
Author: Gary Gregory <ggregory@apache.org>
Authored: Sun Oct 23 10:59:16 2016 -0700
Committer: Gary Gregory <ggregory@apache.org>
Committed: Sun Oct 23 10:59:16 2016 -0700

----------------------------------------------------------------------
 .../apache/commons/lang3/SerializationUtils.java    | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/151f2cd3/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 9e60e69..aadea86 100644
--- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
@@ -81,10 +81,8 @@ public class SerializationUtils {
         final byte[] objectData = serialize(object);
         final ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
 
-        ClassLoaderAwareObjectInputStream in = null;
-        try {
-            // stream closed in the finally
-            in = new ClassLoaderAwareObjectInputStream(bais, object.getClass().getClassLoader());
+        try (ClassLoaderAwareObjectInputStream in = new ClassLoaderAwareObjectInputStream(bais,
+                object.getClass().getClassLoader())) {
             /*
              * when we serialize and deserialize an object,
              * it is reasonable to assume the deserialized object
@@ -97,15 +95,7 @@ public class SerializationUtils {
         } catch (final ClassNotFoundException ex) {
             throw new SerializationException("ClassNotFoundException while reading cloned
object data", ex);
         } catch (final IOException ex) {
-            throw new SerializationException("IOException while reading cloned object data",
ex);
-        } finally {
-            try {
-                if (in != null) {
-                    in.close();
-                }
-            } catch (final IOException ex) {
-                throw new SerializationException("IOException on closing cloned object data
InputStream.", ex);
-            }
+            throw new SerializationException("IOException while reading or closing cloned
object data", ex);
         }
     }
 


Mime
View raw message