You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2013/05/02 01:41:51 UTC

svn commit: r1478232 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java

Author: sebb
Date: Wed May  1 23:41:44 2013
New Revision: 1478232

URL: http://svn.apache.org/r1478232
Log:
Eliminate one unchecked warning; localise and document others

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java?rev=1478232&r1=1478231&r2=1478232&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java Wed May  1 23:41:44 2013
@@ -197,8 +197,6 @@ public class SerializationUtils {
      * @throws SerializationException
      *             (runtime) if the serialization fails
      */
-    @SuppressWarnings("unchecked")
-    // Don't warn about "(T) deserialize" because we want the avoid type casting call sites.
     public static <T> T deserialize(final InputStream inputStream) {
         if (inputStream == null) {
             throw new IllegalArgumentException("The InputStream must not be null");
@@ -207,8 +205,12 @@ public class SerializationUtils {
         try {
             // stream closed in the finally
             in = new ObjectInputStream(inputStream);
-            return (T) in.readObject();
+            @SuppressWarnings("unchecked") // may fail with CCE if serialised form is incorrect
+            final T obj = (T) in.readObject();
+            return obj;
 
+        } catch (final ClassCastException ex) {
+            throw new SerializationException(ex);
         } catch (final ClassNotFoundException ex) {
             throw new SerializationException(ex);
         } catch (final IOException ex) {
@@ -244,13 +246,11 @@ public class SerializationUtils {
      * @throws SerializationException
      *             (runtime) if the serialization fails
      */
-    @SuppressWarnings("unchecked")
-    // Don't warn about "(T) deserialize" because we want the avoid type casting call sites.
     public static <T> T deserialize(final byte[] objectData) {
         if (objectData == null) {
             throw new IllegalArgumentException("The byte[] must not be null");
         }
-        return (T) deserialize(new ByteArrayInputStream(objectData));
+        return org.apache.commons.lang3.SerializationUtils.<T>deserialize(new ByteArrayInputStream(objectData));
     }
 
     /**