diff --git a/common/source/java/ch/systemsx/cisd/common/test/InterfaceForRMIChecker.java b/common/source/java/ch/systemsx/cisd/common/test/InterfaceForRMIChecker.java index 738f05fab8803d381065cabae2e09bd15d9b3d64..73d0465f5e8a60b2eccd25137074247ecb8bdeaf 100644 --- a/common/source/java/ch/systemsx/cisd/common/test/InterfaceForRMIChecker.java +++ b/common/source/java/ch/systemsx/cisd/common/test/InterfaceForRMIChecker.java @@ -57,12 +57,12 @@ public class InterfaceForRMIChecker Class<?>[] parameterTypes = method.getParameterTypes(); for (Class<?> parameterType : parameterTypes) { - assertSerializable(parameterType, visitedClasses); + assertSerializable(parameterType, visitedClasses, true); } Class<?> returnType = method.getReturnType(); if (Void.class.isAssignableFrom(returnType) == false) { - assertSerializable(returnType, visitedClasses); + assertSerializable(returnType, visitedClasses, true); } } @@ -74,10 +74,10 @@ public class InterfaceForRMIChecker */ public static void assertSerializable(Class<?> clazz) { - assertSerializable(clazz, new HashSet<Class<?>>()); + assertSerializable(clazz, new HashSet<Class<?>>(), true); } - private static void assertSerializable(Class<?> clazz, Set<Class<?>> visitedClasses) + private static void assertSerializable(Class<?> clazz, Set<Class<?>> visitedClasses, boolean checkImplementsSerializable) { assert clazz != null : "Unspecified class."; if (clazz.isPrimitive() || visitedClasses.contains(clazz)) @@ -87,10 +87,13 @@ public class InterfaceForRMIChecker visitedClasses.add(clazz); if (clazz.isArray()) { - assertSerializable(clazz.getComponentType(), visitedClasses); + assertSerializable(clazz.getComponentType(), visitedClasses, true); } else { - assert Serializable.class.isAssignableFrom(clazz) : clazz + " does not implements java.io.Serializable"; + if (checkImplementsSerializable) + { + assert Serializable.class.isAssignableFrom(clazz) : clazz + " does not implements java.io.Serializable"; + } Field[] fields = clazz.getDeclaredFields(); for (Field field : fields) { @@ -103,7 +106,7 @@ public class InterfaceForRMIChecker Class<?> attributeClass = field.getType(); if (attributeClass.isInterface() == false) { - assertSerializable(attributeClass, visitedClasses); + assertSerializable(attributeClass, visitedClasses, true); } else { Type genericType = field.getGenericType(); @@ -115,7 +118,7 @@ public class InterfaceForRMIChecker { if (type instanceof Class<?>) { - assertSerializable((Class<?>) type, visitedClasses); + assertSerializable((Class<?>) type, visitedClasses, true); } } } @@ -125,7 +128,7 @@ public class InterfaceForRMIChecker Class<?> superclass = clazz.getSuperclass(); if (superclass != null && superclass.equals(Object.class) == false) { - assertSerializable(superclass, visitedClasses); + assertSerializable(superclass, visitedClasses, false); } } } diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/test/InterfaceForRMICheckerTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/test/InterfaceForRMICheckerTest.java index 317f131446410df53cc24febdde13cfc0e391da9..21b5e97c7bb9b80cee8985f77253a5d9fd7be9a0 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/test/InterfaceForRMICheckerTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/test/InterfaceForRMICheckerTest.java @@ -112,6 +112,27 @@ public class InterfaceForRMICheckerTest } } + @Test + public void testSerializablityOfSerializableClassExtendsNonSerializableClass() + { + InterfaceForRMIChecker.assertSerializable(SerializableClassExtendsNonSerializableClass.class); + } + + public static class SerializableClassExtendsNonSerializableClass extends NonSerializableClass implements Serializable + { + private static final long serialVersionUID = 1L; + private static NonSerializableClass non; + private int n; + private transient NonSerializableClass transientNon; + public List<String> list; + + @Override + public String toString() + { + return non.toString() + n + transientNon; + } + } + @Test public void testSerializablityOfNonSerializableClass() {