camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10376 BeanInfo should prefer implementation methods instead of bridged methods
Date Thu, 13 Oct 2016 08:22:56 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 467ded8f3 -> 92630afb2


CAMEL-10376 BeanInfo should prefer implementation methods instead of bridged methods


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/803f7e56
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/803f7e56
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/803f7e56

Branch: refs/heads/camel-2.18.x
Commit: 803f7e56302dca9171a94ceb6d381071725ae756
Parents: 467ded8
Author: Babur Duisenov <bduisenov@gmail.com>
Authored: Mon Oct 10 15:46:09 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Oct 13 10:22:08 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/component/bean/BeanInfo.java   | 18 +++--
 .../bean/BeanInfoWithBridgedMethodTest.java     | 71 ++++++++++++++++++++
 2 files changed, 85 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/803f7e56/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index 87be7ee..1fc4404 100644
--- a/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -328,13 +328,18 @@ public class BeanInfo {
         }
 
         Set<Method> overrides = new HashSet<Method>();
-        Set<Method> bridges = new HashSet<Method>();
 
         // do not remove duplicates form class from the Java itself as they have some "duplicates"
we need
         boolean javaClass = clazz.getName().startsWith("java.") || clazz.getName().startsWith("javax.");
         if (!javaClass) {
             // it may have duplicate methods already, even from declared or from interfaces
+ declared
             for (Method source : methods) {
+
+                // skip bridge methods in duplicate checks (as the bridge method is inserted
by the compiler due to type erasure)
+                if (source.isBridge()) {
+                    continue;
+                }
+
                 for (Method target : methods) {
                     // skip ourselves
                     if (ObjectHelper.isOverridingMethod(source, target, true)) {
@@ -354,10 +359,15 @@ public class BeanInfo {
         if (Modifier.isPublic(clazz.getModifiers())) {
             // add additional interface methods
             List<Method> extraMethods = getInterfaceMethods(clazz);
-            for (Method target : extraMethods) {
-                for (Method source : methods) {
+            for (Method source : extraMethods) {
+                for (Method target : methods) {
                     if (ObjectHelper.isOverridingMethod(source, target, false)) {
-                        overrides.add(target);
+                        overrides.add(source);
+                    }
+                }
+                for (Method target : methodMap.keySet()) {
+                    if (ObjectHelper.isOverridingMethod(source, target, false)) {
+                        overrides.add(source);
                     }
                 }
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/803f7e56/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoWithBridgedMethodTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoWithBridgedMethodTest.java
b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoWithBridgedMethodTest.java
new file mode 100644
index 0000000..813c11e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/bean/BeanInfoWithBridgedMethodTest.java
@@ -0,0 +1,71 @@
+package org.apache.camel.component.bean;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Service;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * Unit test for bridged methods.
+ */
+public class BeanInfoWithBridgedMethodTest extends ContextTestSupport {
+
+    public void testBridgedMethod() throws Exception {
+        BeanInfo beanInfo = new BeanInfo(context, MyService.class);
+
+        DefaultExchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody(new Request(1));
+
+        try {
+            MyService myService = new MyService();
+            MethodInvocation mi = beanInfo.createInvocation(null, exchange);
+            assertEquals("MyService", mi.getMethod().getDeclaringClass().getSimpleName());
+            assertEquals(2, mi.getMethod().invoke(myService, new Request(1)));
+        } catch (AmbiguousMethodCallException e) {
+            fail("This should not be ambiguous!");
+        }
+    }
+
+    public void testPackagePrivate() throws Exception {
+        BeanInfo beanInfo = new BeanInfo(context, MyPackagePrivateService.class);
+
+        DefaultExchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody(new Request(1));
+
+        try {
+            MyPackagePrivateService myService = new MyPackagePrivateService();
+            MethodInvocation mi = beanInfo.createInvocation(null, exchange);
+            assertEquals("Service", mi.getMethod().getDeclaringClass().getSimpleName());
+            assertEquals(4, mi.getMethod().invoke(myService, new Request(2)));
+        } catch (AmbiguousMethodCallException e) {
+            fail("This should not be ambiguous!");
+        }
+    }
+
+    public static class Request {
+        int x;
+
+        public Request(int x) {
+            this.x = x;
+        }
+    }
+
+    public interface Service<R> {
+
+        int process(R request);
+    }
+
+    public static class MyService implements Service<Request> {
+
+        public int process(Request request) {
+            return request.x + 1;
+        }
+    }
+
+    static class MyPackagePrivateService implements Service<Request> {
+
+        public int process(Request request) {
+            return request.x + 2;
+        }
+    }
+
+}


Mime
View raw message