You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2020/07/26 21:30:33 UTC

[tapestry-5] branch master updated: TAP5-2633: ChainBuilder fails with interface containing static methods

This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c34d4d  TAP5-2633: ChainBuilder fails with interface containing static methods
4c34d4d is described below

commit 4c34d4d6f501bca565acff14b20708f2b10ba6d8
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sun Jul 26 18:30:20 2020 -0300

    TAP5-2633: ChainBuilder fails with interface containing static methods
---
 .../ioc/internal/services/ChainBuilderImpl.java    |  6 ++++-
 .../groovy/ioc/specs/ChainBuilderImplSpec.groovy   | 18 +++++++++++++++
 .../ioc/internal/InterfaceWithStaticMethod.java    | 27 ++++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImpl.java
index 07be24f..1bfdeac 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/ChainBuilderImpl.java
@@ -16,6 +16,7 @@ package org.apache.tapestry5.ioc.internal.services;
 
 import java.lang.reflect.Array;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.List;
 
 import org.apache.tapestry5.ioc.services.Builtin;
@@ -60,7 +61,10 @@ public class ChainBuilderImpl implements ChainBuilder
 
                 for (Method method : commandInterface.getMethods())
                 {
-                    implementMethod(plasticClass, method, commandsField);
+                    if (!Modifier.isStatic(method.getModifiers()))
+                    {
+                        implementMethod(plasticClass, method, commandsField);
+                    }
                 }
 
                 plasticClass.addToString(String.format("<Command chain of %s>", commandInterface.getName()));
diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/ChainBuilderImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/ChainBuilderImplSpec.groovy
index 7638df0..12ff3a7 100644
--- a/tapestry-ioc/src/test/groovy/ioc/specs/ChainBuilderImplSpec.groovy
+++ b/tapestry-ioc/src/test/groovy/ioc/specs/ChainBuilderImplSpec.groovy
@@ -1,6 +1,7 @@
 package ioc.specs
 
 import org.apache.tapestry5.ioc.services.ChainBuilder
+import org.apache.tapestry5.ioc.internal.InterfaceWithStaticMethod
 
 interface ChainCommand {
 
@@ -116,6 +117,23 @@ class ChainBuilderImplSpec extends AbstractSharedRegistrySpecification {
 
     chain.toString() == "<Command chain of ioc.specs.ChainCommand>"
   }
+  
+  final private static class InterfaceWithStaticMethodImpl extends InterfaceWithStaticMethod 
+  {
+    public int something() { return 2; }
+  }
+
+  /* Blows up without fix. */
+  def "chain interface has static method"() {
+    InterfaceWithStaticMethod c1 = Mock()
+    InterfaceWithStaticMethod c2 = new InterfaceWithStaticMethodImpl()
 
+    when:
+      InterfaceWithStaticMethod chain = getService(ChainBuilder).build(InterfaceWithStaticMethod, [c1, c2])
+    then: 
+      chain.something() == 2
+      chain.defaultSomething() == 1
+  
+  }
 
 }
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/InterfaceWithStaticMethod.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/InterfaceWithStaticMethod.java
new file mode 100644
index 0000000..d27d238
--- /dev/null
+++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/InterfaceWithStaticMethod.java
@@ -0,0 +1,27 @@
+// Copyright 2020 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.internal;
+
+public interface InterfaceWithStaticMethod {
+
+    int something();
+    
+    static void staticSomething() {}
+    
+    default int defaultSomething() 
+    {
+        return 1; 
+    }; 
+    
+}