TAP5-2588: not proxying interface static methods. Patch provided by Dmitrios Zenios
authorThiago H. de Paula Figueiredo <thiago@arsmachina.com.br>
Wed, 5 Dec 2018 23:26:05 +0000 (21:26 -0200)
committerThiago H. de Paula Figueiredo <thiago@arsmachina.com.br>
Wed, 5 Dec 2018 23:26:05 +0000 (21:26 -0200)
plastic/src/main/java/org/apache/tapestry5/internal/plastic/PlasticClassImpl.java
plastic/src/test/groovy/org/apache/tapestry5/plastic/MethodProxying.groovy
plastic/src/test/java/testinterfaces/WithStatic.java [new file with mode: 0644]
tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java

index 223109a..b86b8d0 100644 (file)
@@ -619,15 +619,15 @@ public class PlasticClassImpl extends Lockable implements PlasticClass, Internal
         introduceInterface(interfaceType);
 
         // TAP5-2582: avoiding adding/delegating the same method more than once
-//        for (Method m : interfaceType.getMethods())
-//        {
-//            introduceMethod(m).delegateTo(field);
-//        }
-
         Map<MethodSignature, MethodDescription> map = createMethodSignatureMap(interfaceType);
         for (MethodSignature methodSignature : map.keySet())
         {
-            introduceMethod(map.get(methodSignature)).delegateTo(field);
+            final MethodDescription description = map.get(methodSignature);
+            if(Modifier.isStatic(description.modifiers))
+            {
+                continue;
+            }
+            introduceMethod(description).delegateTo(field);
         }
 
         return this;
@@ -646,6 +646,11 @@ public class PlasticClassImpl extends Lockable implements PlasticClass, Internal
         Map<MethodSignature, MethodDescription> map = createMethodSignatureMap(interfaceType);
         for (MethodSignature methodSignature : map.keySet())
         {
+            final MethodDescription description = map.get(methodSignature);
+            if(Modifier.isStatic(description.modifiers))
+            {
+                continue;
+            }
             introduceMethod(map.get(methodSignature)).delegateTo(method);
         }
 
@@ -1456,7 +1461,7 @@ public class PlasticClassImpl extends Lockable implements PlasticClass, Internal
             // MethodDescription description = new MethodDescription(m);
             final MethodDescription description = map.get(methodSignature);
 
-            if (!isMethodImplemented(description) && !isDefaultMethod(methodSignature.method))
+            if (!isMethodImplemented(description) && !isDefaultMethod(methodSignature.method) && !Modifier.isStatic(description.modifiers))
             {
                 // introducedMethods.add(introduceMethod(m));
                 introducedMethods.add(introduceMethod(description));
index 512508d..22e41b6 100644 (file)
@@ -1,6 +1,7 @@
 package org.apache.tapestry5.plastic
 
 import testsubjects.Memory
+import testinterfaces.WithStatic
 
 class MethodProxying extends AbstractPlasticSpecification {
 
@@ -29,6 +30,32 @@ class MethodProxying extends AbstractPlasticSpecification {
         1 * mockRunnable.run()
     }
 
+    def "Proxying with static methods"() {
+        setup:
+
+        def mockRunnable = Mock(Runnable.class)
+
+        def o = mgr.createClass(Object, { PlasticClass pc ->
+
+            def field = pc.introduceField(Runnable, "delegate").inject(mockRunnable)
+
+            pc.proxyInterface(WithStatic, field)
+        } as PlasticClassTransformer).newInstance()
+
+        expect:
+
+        WithStatic.isInstance o
+        o.version() == 1
+
+        when:
+
+        o.run()
+
+        then:
+
+        1 * mockRunnable.run()
+    }
+
     def "proxy method with arguments and return value"() {
         setup:
 
diff --git a/plastic/src/test/java/testinterfaces/WithStatic.java b/plastic/src/test/java/testinterfaces/WithStatic.java
new file mode 100644 (file)
index 0000000..e3150f3
--- /dev/null
@@ -0,0 +1,7 @@
+package testinterfaces;
+
+public interface WithStatic extends Runnable {
+    static int version() {
+        return 1;
+    }
+}
index 51f864c..37ce2bf 100644 (file)
@@ -510,10 +510,6 @@ public class ModuleImpl implements Module
                 });
 
                 plasticClass.proxyInterface(serviceInterface, delegateMethod);
-//                for (Method m : serviceInterface.getMethods())
-//                {
-//                    plasticClass.introduceMethod(m).delegateTo(delegateMethod);
-//                }
 
                 plasticClass.introduceMethod(WRITE_REPLACE).changeImplementation(new InstructionBuilderCallback()
                 {