aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1143912 - in /aries/trunk/proxy/proxy-impl/src: main/java/org/apache/aries/proxy/impl/common/ main/java/org/apache/aries/proxy/impl/weaving/ test/java/org/apache/aries/blueprint/proxy/
Date Thu, 07 Jul 2011 16:40:25 GMT
Author: timothyjward
Date: Thu Jul  7 16:40:25 2011
New Revision: 1143912

URL: http://svn.apache.org/viewvc?rev=1143912&view=rev
Log:
ARIES-705 : Avoid generating a serialVersionUID for classes that aren't Serializable

Modified:
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyAdapter.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=1143912&r1=1143911&r2=1143912&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
Thu Jul  7 16:40:25 2011
@@ -19,9 +19,11 @@
 package org.apache.aries.proxy.impl.common;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.lang.reflect.Modifier;
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -160,6 +162,11 @@ public abstract class AbstractWovenProxy
    */
   private boolean hasNoArgsConstructor = false;
   /**
+   * If we have a no-args constructor then we can delegate there rather than 
+   * to a super no-args
+   */
+  protected boolean isSerializable = false;
+  /**
    * The default static initialization method where we will write the proxy init
    * code. If there is an existing <clinit> then we will change this and write a
    * static_init_UUID instead (see the overriden 
@@ -214,6 +221,9 @@ public abstract class AbstractWovenProxy
       Class<?> superClass = Class.forName(superName.replace('/', '.'), false,
           loader);
 
+      isSerializable = Serializable.class.isAssignableFrom(superClass) || 
+                       Arrays.asList(interfaces).contains(Type.getInternalName(Serializable.class));
+      
       if (!!!WovenProxy.class.isAssignableFrom(superClass)) {
 
         // We have found a type we need to add WovenProxy information to

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyAdapter.java?rev=1143912&r1=1143911&r2=1143912&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyAdapter.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyAdapter.java
Thu Jul  7 16:40:25 2011
@@ -61,9 +61,17 @@ final class WovenProxyAdapter extends Ab
   @Override
   public FieldVisitor visitField(int access, String name, String arg2,
       String arg3, Object arg4) {
+    
     //If this sVUID is generated then make it synthetic
-    if(sVUIDGenerated && "serialVersionUID".equals(name)) 
+    if(sVUIDGenerated && "serialVersionUID".equals(name)) {
+      
+      //If we aren't a serializable class then don't add a generated sVUID
+      if(!!!isSerializable) {
+        return null;
+      }
+      
       access |= ACC_SYNTHETIC;
+    }
     return super.visitField(access, name, arg2, arg3, arg4);
   }
 

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=1143912&r1=1143911&r2=1143912&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
Thu Jul  7 16:40:25 2011
@@ -313,6 +313,12 @@ public class WovenProxyGeneratorTest ext
     }
   }
   
+  @Test(expected=NoSuchFieldException.class)
+  public void testNonSerializableClassHasNoGeneratedSerialVersionUID() throws Exception {
+    Class<?> woven = getProxyClass(TEST_CLASS);
+    woven.getDeclaredField("serialVersionUID");
+  }
+  
   @Test
   public void testSerialization() throws Exception {
     



Mime
View raw message