aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From timothyjw...@apache.org
Subject svn commit: r1094472 - in /aries/trunk/proxy/proxy-impl/src: main/java/org/apache/aries/proxy/impl/weaving/ test/java/org/apache/aries/blueprint/proxy/
Date Mon, 18 Apr 2011 10:31:54 GMT
Author: timothyjward
Date: Mon Apr 18 10:31:53 2011
New Revision: 1094472

URL: http://svn.apache.org/viewvc?rev=1094472&view=rev
Log:
ARIES-633 : Fix bug with interface inheritance and fields on interfaces

Added:
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
Modified:
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/InterfaceCombiningClassAdapter.java
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/InterfaceCombiningClassAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/InterfaceCombiningClassAdapter.java?rev=1094472&r1=1094471&r2=1094472&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/InterfaceCombiningClassAdapter.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/InterfaceCombiningClassAdapter.java
Mon Apr 18 10:31:53 2011
@@ -20,6 +20,7 @@ package org.apache.aries.proxy.impl.weav
 
 import java.io.IOException;
 import java.lang.reflect.Constructor;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Map;
@@ -146,8 +147,10 @@ public final class InterfaceCombiningCla
     //We're going to implement this method, so make it non abstract!
     access ^= ACC_ABSTRACT;
     //If we already implement this method (from another interface) then we don't
-    //want a duplicate
-    if(adapter.knownMethods.contains(new Method(name, desc)))
+    //want a duplicate. We also don't want to copy any static init blocks (these
+    //initialize static fields on the interface that we don't copy
+    if(adapter.knownMethods.contains(new Method(name, desc)) || 
+        "<clinit>".equals(name))
       return null;
     else 
       return adapter.visitMethod(access, name, desc, null, arg4);
@@ -192,7 +195,7 @@ public final class InterfaceCombiningCla
     
     Class<?> c;
     
-    HashSet<Class<?>> classes = new HashSet<Class<?>>(ifaces);
+    HashSet<Class<?>> classes = createSet(ifaces);
     
     c = cache.get(classes);
     
@@ -240,4 +243,21 @@ public final class InterfaceCombiningCla
       throw new UnableToProxyException(classes.iterator().next(), e);
     }
   }
+
+  /**
+   * Get the set of interfaces we need to process. This will return a HashSet 
+   * that includes includes the supplied collection and any super-interfaces of 
+   * those classes 
+   * @param ifaces
+   * @return
+   */
+  private static HashSet<Class<?>> createSet(Collection<Class<?>>
ifaces) {
+    HashSet<Class<?>> classes = new HashSet<Class<?>>();
+    for(Class<?> c : ifaces) {
+      //If we already have a class contained then we have already covered its hierarchy
+      if(classes.add(c))
+        classes.addAll(createSet(Arrays.asList(c.getInterfaces())));
+    }
+    return classes;
+  }
 }
\ No newline at end of file

Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java?rev=1094472&r1=1094471&r2=1094472&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
Mon Apr 18 10:31:53 2011
@@ -182,6 +182,29 @@ public class InterfaceProxyingTest {
     assertSame(o1.getClass(), o2.getClass());
   }
   
+  @Test
+  public void testComplexInterface() throws Exception {
+    Collection<Class<?>> classes = new ArrayList<Class<?>>(Arrays.asList(ProxyTestInterface.class));
+    
+    final TestCallable tc = new TestCallable();
+    tc.setReturn(5);
+    
+    Object o = InterfaceCombiningClassAdapter.getProxyInstance(classes, 
+        new Callable<Object>() {
+
+          @Override
+          public Object call() throws Exception {
+            return tc;
+          }
+    }, null);
+    
+    assertTrue(o instanceof ProxyTestInterface);
+    
+    assertTrue(o instanceof Callable);
+    
+    assertEquals(5, ((Callable)o).call());
+  }
+  
   protected void assertCalled(TestListener listener, boolean pre, boolean post, boolean ex)
{
     assertEquals(pre, listener.preInvoke);
     assertEquals(post, listener.postInvoke);

Added: 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=1094472&view=auto
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
(added)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestInterface.java
Mon Apr 18 10:31:53 2011
@@ -0,0 +1,10 @@
+package org.apache.aries.blueprint.proxy;
+
+import java.util.concurrent.Callable;
+
+public interface ProxyTestInterface extends Callable<Object> {
+
+  public static final String FIELD = "A Field";
+  
+  public int doSuff();
+}



Mime
View raw message