diff options
author | Sebastian Bazley <sebb@apache.org> | 2013-05-01 23:41:44 +0000 |
---|---|---|
committer | Sebastian Bazley <sebb@apache.org> | 2013-05-01 23:41:44 +0000 |
commit | 5c2471f8969aa02a560b13f1e8820389a59740dd (patch) | |
tree | 845e5e209c97aa633f3a5fad7c574982312ab721 /src/main/java/org/apache/commons/lang3/SerializationUtils.java | |
parent | e3982f893fcd2cd572bbec8e3a4a97ec328c5c9e (diff) | |
download | apache-commons-lang-5c2471f8969aa02a560b13f1e8820389a59740dd.tar.gz |
Eliminate one unchecked warning; localise and document others
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1478232 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/SerializationUtils.java')
-rw-r--r-- | src/main/java/org/apache/commons/lang3/SerializationUtils.java | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java b/src/main/java/org/apache/commons/lang3/SerializationUtils.java index 7e95e28bb..8d8353a86 100644 --- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java +++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java @@ -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)); } /** |