Hello Duncan,

2015-04-08 10:38 GMT+02:00 <djo...@apache.org>:

> Author: djones
> Date: Wed Apr  8 08:38:02 2015
> New Revision: 1672030
>
> URL: http://svn.apache.org/r1672030
> Log:
> Suppressed two unchecked warnings.
>
> Modified:
>
> commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/SerializationUtils.java
>
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.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=1672030&r1=1672029&r2=1672030&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 Apr  8 08:38:02 2015
> @@ -121,6 +121,7 @@ public class SerializationUtils {
>       * @return the serialized and deseralized object
>       * @since 3.3
>       */
> +    @SuppressWarnings("unchecked")
>

It's good practice to add a comment explaining why it is safe to suppress
warnings. In this case we can be sure that the result will be of type T,
because we've it is the type of the object we have serialized before.


>      public static <T extends Serializable> T roundtrip(final T msg) {
>          return (T)
> SerializationUtils.deserialize(SerializationUtils.serialize(msg));
>      }
>
> Modified:
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java
> URL:
> http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java?rev=1672030&r1=1672029&r2=1672030&view=diff
>
> ==============================================================================
> ---
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java
> (original)
> +++
> commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/exception/AbstractExceptionContextTest.java
> Wed Apr  8 08:38:02 2015
> @@ -18,7 +18,9 @@ package org.apache.commons.lang3.excepti
>
>  import org.junit.Test;
>  import org.junit.Before;
> +
>  import static org.junit.Assert.*;
> +
>  import java.io.Serializable;
>  import java.util.Arrays;
>  import java.util.Collections;
> @@ -178,6 +180,7 @@ public abstract class AbstractExceptionC
>      public void testJavaSerialization() {
>          exceptionContext.setContextValue("test Poorly written obj",
> "serializable replacement");
>
> +        @SuppressWarnings("unchecked")
>          final T clone = (T)
> SerializationUtils.deserialize(SerializationUtils.serialize(exceptionContext));
>          assertEquals(exceptionContext.getFormattedExceptionMessage(null),
> clone.getFormattedExceptionMessage(null));
>      }
>
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Reply via email to