You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/05/25 19:23:47 UTC

[commons-lang] branch master updated: Remove some @SuppressWarnings.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new 357951f  Remove some @SuppressWarnings.
357951f is described below

commit 357951ff5c28dbd724611e8d41e23686f09a164a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue May 25 15:23:43 2021 -0400

    Remove some @SuppressWarnings.
---
 .../java/org/apache/commons/lang3/ObjectUtils.java   |  7 +++----
 .../org/apache/commons/lang3/SerializationUtils.java | 20 ++++++++------------
 2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/lang3/ObjectUtils.java b/src/main/java/org/apache/commons/lang3/ObjectUtils.java
index 78787fa..fd50655 100644
--- a/src/main/java/org/apache/commons/lang3/ObjectUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ObjectUtils.java
@@ -1082,11 +1082,10 @@ public class ObjectUtils {
         Validate.notEmpty(items, "null/empty items");
         Validate.noNullElements(items);
         Validate.notNull(comparator, "comparator");
-        final TreeSet<T> sort = new TreeSet<>(comparator);
-        Collections.addAll(sort, items);
+        final TreeSet<T> treeSet = new TreeSet<>(comparator);
+        Collections.addAll(treeSet, items);
         @SuppressWarnings("unchecked") //we know all items added were T instances
-        final
-        T result = (T) sort.toArray()[(sort.size() - 1) / 2];
+        final T result = (T) treeSet.toArray()[(treeSet.size() - 1) / 2];
         return result;
     }
 
diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
index 947460d..8db268e 100644
--- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java
+++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java
@@ -138,21 +138,17 @@ public class SerializationUtils {
         final byte[] objectData = serialize(object);
         final ByteArrayInputStream bais = new ByteArrayInputStream(objectData);
 
-        try (ClassLoaderAwareObjectInputStream in = new ClassLoaderAwareObjectInputStream(bais,
-                object.getClass().getClassLoader())) {
+        final Class<T> cls = ObjectUtils.getClass(object);
+        try (ClassLoaderAwareObjectInputStream in = new ClassLoaderAwareObjectInputStream(bais, cls.getClassLoader())) {
             /*
-             * when we serialize and deserialize an object,
-             * it is reasonable to assume the deserialized object
-             * is of the same type as the original serialized object
+             * when we serialize and deserialize an object, it is reasonable to assume the deserialized object is of the
+             * same type as the original serialized object
              */
-            @SuppressWarnings("unchecked") // see above
-            final T readObject = (T) in.readObject();
-            return readObject;
+            return cls.cast(in.readObject());
 
-        } catch (final ClassNotFoundException ex) {
-            throw new SerializationException("ClassNotFoundException while reading cloned object data", ex);
-        } catch (final IOException ex) {
-            throw new SerializationException("IOException while reading or closing cloned object data", ex);
+        } catch (final ClassNotFoundException | IOException ex) {
+            throw new SerializationException(
+                String.format("%s while reading cloned object data", ex.getClass().getSimpleName()), ex);
         }
     }