aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1145576 - in /aries/trunk/proxy/proxy-impl/src: main/java/org/apache/aries/proxy/impl/common/ test/java/org/apache/aries/blueprint/proxy/
Date Tue, 12 Jul 2011 13:09:50 GMT
Author: timothyjward
Date: Tue Jul 12 13:09:50 2011
New Revision: 1145576

URL: http://svn.apache.org/viewvc?rev=1145576&view=rev
Log:
ARIES-705 : Correctly identify Classes as Serializable when they implement interfaces that
extend Serializable rather than by implementing it directly

Added:
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableChild.java
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableInterface.java
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestSerializableInterface.java
Modified:
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java?rev=1145576&r1=1145575&r2=1145576&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
Tue Jul 12 13:09:50 2011
@@ -222,7 +222,8 @@ public abstract class AbstractWovenProxy
           loader);
 
       isSerializable = Serializable.class.isAssignableFrom(superClass) || 
-                       Arrays.asList(interfaces).contains(Type.getInternalName(Serializable.class));
+                       Arrays.asList(interfaces).contains(Type.getInternalName(Serializable.class))
||
+                       checkInterfacesForSerializability(interfaces);
       
       if (!!!WovenProxy.class.isAssignableFrom(superClass)) {
 
@@ -273,6 +274,16 @@ public abstract class AbstractWovenProxy
     }
   }
 
+  private boolean checkInterfacesForSerializability(String[] interfaces) throws ClassNotFoundException
{
+    for(String iface : interfaces)
+    {
+      if(Serializable.class.isAssignableFrom(Class.forName(
+                 iface.replace('/', '.'), false, loader)))
+        return true;
+    }
+    return false;
+  }
+
   /**
    * This method is called on each method implemented on this object (but not
    * for superclass methods) Each of these methods is visited in turn and the

Added: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableChild.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableChild.java?rev=1145576&view=auto
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableChild.java
(added)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableChild.java
Tue Jul 12 13:09:50 2011
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.proxy;
+
+public class ProxyTestClassSerializableChild extends ProxyTestClassSerializable {
+
+}

Added: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableInterface.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableInterface.java?rev=1145576&view=auto
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableInterface.java
(added)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassSerializableInterface.java
Tue Jul 12 13:09:50 2011
@@ -0,0 +1,27 @@
+package org.apache.aries.blueprint.proxy;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
+public class ProxyTestClassSerializableInterface implements
+    ProxyTestSerializableInterface {
+
+  public int value;
+  
+  /**
+   * We deserialize using this static method to ensure that the right classloader
+   * is used when deserializing our object, it will always be the classloader that
+   * loaded this class, which might be the JUnit one, or our weaving one.
+   * 
+   * @param bytes
+   * @param value
+   * @throws Exception
+   */
+  public static void checkDeserialization(byte[] bytes, int value) throws Exception {
+    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
+    ProxyTestClassSerializableInterface out = (ProxyTestClassSerializableInterface) ois.readObject();
+    assertEquals(value, out.value);
+  }
+}

Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java?rev=1145576&r1=1145575&r2=1145576&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
Tue Jul 12 13:09:50 2011
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.aries.blueprint.proxy;
 
 import java.util.concurrent.Callable;

Added: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestSerializableInterface.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestSerializableInterface.java?rev=1145576&view=auto
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestSerializableInterface.java
(added)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestSerializableInterface.java
Tue Jul 12 13:09:50 2011
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.proxy;
+
+import java.io.Serializable;
+
+public interface ProxyTestSerializableInterface extends Serializable {
+
+}

Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java?rev=1145576&r1=1145575&r2=1145576&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
Tue Jul 12 13:09:50 2011
@@ -77,7 +77,8 @@ public class WovenProxyGeneratorTest ext
     ProxyTestClassStaticInner.class, ProxyTestClassUnweavableInnerChild.class, 
     ProxyTestClassUnweavableChildWithFinalMethodParent.class, 
     ProxyTestClassUnweavableChildWithDefaultMethodWrongPackageParent.class, 
-    ProxyTestClassSerializable.class, ProxyTestClassSerializableWithSVUID.class};
+    ProxyTestClassSerializable.class, ProxyTestClassSerializableWithSVUID.class,
+    ProxyTestClassSerializableChild.class, ProxyTestClassSerializableInterface.class};
  
   private static final Map<String, byte[]> rawClasses = new HashMap<String, byte[]>();
   
@@ -337,6 +338,40 @@ public class WovenProxyGeneratorTest ext
   }
   
   @Test
+  public void testInheritedSerialization() throws Exception {
+    
+    ProxyTestClassSerializableChild in = new ProxyTestClassSerializableChild();
+    in.value = 4;
+    
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    ObjectOutputStream oos = new ObjectOutputStream(baos);
+    oos.writeObject(in);
+    
+    ProxyTestClassSerializable.checkDeserialization(baos.toByteArray(), 4);
+
+    Class<?> woven = getProxyClass(ProxyTestClassSerializable.class);
+    
+    woven.getMethod("checkDeserialization", byte[].class, int.class).invoke(null, baos.toByteArray(),
4);
+  }
+  
+  @Test
+  public void testInterfaceInheritedSerialization() throws Exception {
+    
+    ProxyTestClassSerializableInterface in = new ProxyTestClassSerializableInterface();
+    in.value = 3;
+    
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    ObjectOutputStream oos = new ObjectOutputStream(baos);
+    oos.writeObject(in);
+    
+    ProxyTestClassSerializableInterface.checkDeserialization(baos.toByteArray(), 3);
+
+    Class<?> woven = getProxyClass(ProxyTestClassSerializableInterface.class);
+    
+    woven.getMethod("checkDeserialization", byte[].class, int.class).invoke(null, baos.toByteArray(),
3);
+  }
+  
+  @Test
   public void testGeneratedSVUIDisSynthetic() throws Exception {
     
     Class<?> woven = getProxyClass(ProxyTestClassSerializable.class);



Mime
View raw message