Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BC1EAF9EB for ; Wed, 1 May 2013 23:42:15 +0000 (UTC) Received: (qmail 25180 invoked by uid 500); 1 May 2013 23:42:15 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 24999 invoked by uid 500); 1 May 2013 23:42:14 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 24988 invoked by uid 99); 1 May 2013 23:42:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 May 2013 23:42:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 May 2013 23:42:12 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7CD7623888E3; Wed, 1 May 2013 23:41:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1478232 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java Date: Wed, 01 May 2013 23:41:51 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130501234151.7CD7623888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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.deserialize(new ByteArrayInputStream(objectData)); } /**