Repository: tapestry-5 Updated Branches: refs/heads/master df619008f -> 4458dc3aa
TAP5-2302: ignore methods overridden from java.lang.Object in module classes Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/4458dc3a Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/4458dc3a Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/4458dc3a Branch: refs/heads/master Commit: 4458dc3aa020103654c63d69344d77883a4ae21f Parents: df61900 Author: Jochen Kemnade <jochen.kemn...@eddyson.de> Authored: Wed Apr 30 13:38:44 2014 +0200 Committer: Jochen Kemnade <jochen.kemn...@eddyson.de> Committed: Wed Apr 30 13:40:02 2014 +0200 ---------------------------------------------------------------------- .../ioc/internal/DefaultModuleDefImpl.java | 34 +++++++++++++++- .../ioc/specs/DefaultModuleDefImplSpec.groovy | 12 ++++++ .../ModuleWithOverriddenObjectMethods.java | 42 ++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4458dc3a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java index eca6b7d..be3c3ee 100644 --- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java +++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java @@ -119,7 +119,20 @@ public class DefaultModuleDefImpl implements ModuleDef2, ServiceDefAccumulator Set<Method> methods = CollectionFactory.newSet(moduleClass.getMethods()); - methods.removeAll(OBJECT_METHODS); + Iterator<Method> methodIterator = methods.iterator(); + + while (methodIterator.hasNext()) + { + Method method = methodIterator.next(); + for (Method objectMethod : OBJECT_METHODS) + { + if (signaturesAreEqual(method, objectMethod)) + { + methodIterator.remove(); + } + } + } + removeSyntheticMethods(methods); boolean modulePreventsServiceDecoration = moduleClass.getAnnotation(PreventServiceDecoration.class) != null; @@ -134,6 +147,25 @@ public class DefaultModuleDefImpl implements ModuleDef2, ServiceDefAccumulator moduleClass.getName(), InternalUtils.joinSorted(methods))); } + private static boolean signaturesAreEqual(Method m1, Method m2) + { + if (m1.getName() == m2.getName()) { + if (!m1.getReturnType().equals(m2.getReturnType())) + return false; + Class<?>[] params1 = m1.getParameterTypes(); + Class<?>[] params2 = m2.getParameterTypes(); + if (params1.length == params2.length) + { + for (int i = 0; i < params1.length; i++) { + if (params1[i] != params2[i]) + return false; + } + return true; + } + } + return false; + } + /** * Identifies the module class and a list of service ids within the module. */ http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4458dc3a/tapestry-ioc/src/test/groovy/ioc/specs/DefaultModuleDefImplSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/groovy/ioc/specs/DefaultModuleDefImplSpec.groovy b/tapestry-ioc/src/test/groovy/ioc/specs/DefaultModuleDefImplSpec.groovy index d017dfc..5600ed0 100644 --- a/tapestry-ioc/src/test/groovy/ioc/specs/DefaultModuleDefImplSpec.groovy +++ b/tapestry-ioc/src/test/groovy/ioc/specs/DefaultModuleDefImplSpec.groovy @@ -424,6 +424,18 @@ class DefaultModuleDefImplSpec extends Specification { md.serviceIds.size() == 1 } + + def "Methods overridden from Object are ignored"() { + + when: + + def md = module ModuleWithOverriddenObjectMethods + + then: + + md.serviceIds.size() == 1 + } + private createSyntheticModuleClass() { http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/4458dc3a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleWithOverriddenObjectMethods.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleWithOverriddenObjectMethods.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleWithOverriddenObjectMethods.java new file mode 100644 index 0000000..3999820 --- /dev/null +++ b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/ModuleWithOverriddenObjectMethods.java @@ -0,0 +1,42 @@ +// Copyright 2006, 2007, 2009 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; + +/** + * Used by {@link org.apache.tapestry5.ioc.internal.DefaultModuleDefImplTest}. + */ +public class ModuleWithOverriddenObjectMethods +{ + public static Object build() + { + return new Object(); + } + + @Override + public int hashCode() { + return 23; + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + + @Override + public String toString() { + return "This is a module class that overrides Object methods"; + } + +}