From 426b8e7b4ff31b44b3caa0a07fff54d53729b995 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Thu, 15 Nov 2007 08:48:36 +0000
Subject: [PATCH] bug fixed

SVN: 2570
---
 .../common/test/InterfaceForRMIChecker.java   | 21 +++++++++++--------
 .../test/InterfaceForRMICheckerTest.java      | 21 +++++++++++++++++++
 2 files changed, 33 insertions(+), 9 deletions(-)

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 738f05fab88..73d0465f5e8 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 317f1314464..21b5e97c7bb 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()
     {
-- 
GitLab