You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/10/12 11:01:34 UTC
[1/2] camel git commit: CAMEL-10376 BeanInfo should prefer
implementation methods instead of bridged methods
Repository: camel
Updated Branches:
refs/heads/master ab3e17b73 -> 4d917dfd5
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/8f0c1541
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8f0c1541
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8f0c1541
Branch: refs/heads/master
Commit: 8f0c15413369d245314fe27f34ea16c1ebc854e2
Parents: ab3e17b
Author: Babur Duisenov <bd...@gmail.com>
Authored: Mon Oct 10 15:46:09 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Oct 12 12:57:33 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/8f0c1541/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/8f0c1541/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;
+ }
+ }
+
+}
[2/2] camel git commit: Fixed CS. This closes #1204
Posted by da...@apache.org.
Fixed CS. This closes #1204
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4d917dfd
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4d917dfd
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4d917dfd
Branch: refs/heads/master
Commit: 4d917dfd521693db85c29ea6272092d8c9279f42
Parents: 8f0c154
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Oct 12 13:01:26 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Oct 12 13:01:26 2016 +0200
----------------------------------------------------------------------
.../bean/BeanInfoWithBridgedMethodTest.java | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4d917dfd/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
index 813c11e..61db8ec 100644
--- 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
@@ -1,3 +1,19 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.camel.component.bean;
import org.apache.camel.ContextTestSupport;