This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 21602570573d CAMEL-24102: camel-bean - AmbiguousMethodCallException
lists actual candidates
21602570573d is described below
commit 21602570573d8edc601c054e3696f97273f23252
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Jul 16 15:49:21 2026 +0200
CAMEL-24102: camel-bean - AmbiguousMethodCallException lists actual
candidates
Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
.../org/apache/camel/component/bean/BeanInfo.java | 8 +--
.../bean/BeanAmbiguousBodyConversionTest.java | 67 ++++++++++++++++++++++
2 files changed, 71 insertions(+), 4 deletions(-)
diff --git
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index 904e8cfdfdbf..9619d58b9ba1 100644
---
a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++
b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -885,7 +885,7 @@ public class BeanInfo {
// let's try converting
Object newBody = null;
MethodInfo matched = null;
- int matchCounter = 0;
+ List<MethodInfo> candidates = new ArrayList<>();
for (MethodInfo methodInfo : operationList) {
if (methodInfo.getBodyParameterType() != null) {
if (methodInfo.getBodyParameterType().isInstance(body)) {
@@ -900,14 +900,14 @@ public class BeanInfo {
LOG.trace("Converted body from: {} to: {}",
body.getClass().getCanonicalName(),
methodInfo.getBodyParameterType().getCanonicalName());
}
- matchCounter++;
+ candidates.add(methodInfo);
newBody = value;
matched = methodInfo;
}
}
}
- if (matchCounter > 1) {
- throw new AmbiguousMethodCallException(exchange,
Arrays.asList(matched, matched));
+ if (candidates.size() > 1) {
+ throw new AmbiguousMethodCallException(exchange, candidates);
}
if (matched != null) {
LOG.trace("Setting converted body: {}", body);
diff --git
a/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanAmbiguousBodyConversionTest.java
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanAmbiguousBodyConversionTest.java
new file mode 100644
index 000000000000..72916869487c
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/component/bean/BeanAmbiguousBodyConversionTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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 java.util.Collection;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class BeanAmbiguousBodyConversionTest extends ContextTestSupport {
+
+ @Test
+ public void testAmbiguousExceptionListsDistinctCandidates() {
+ CamelExecutionException e = assertThrows(CamelExecutionException.class,
+ () -> template.sendBody("direct:start", "123"));
+
+ AmbiguousMethodCallException cause =
assertInstanceOf(AmbiguousMethodCallException.class, e.getCause());
+ Collection<MethodInfo> methods = cause.getMethods();
+
+ assertEquals(2, methods.size(), "Should list exactly two distinct
candidates");
+ assertThat(methods).doesNotHaveDuplicates();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:start")
+ .bean(MyAmbiguousBean.class)
+ .to("mock:result");
+ }
+ };
+ }
+
+ @SuppressWarnings("unused")
+ public static class MyAmbiguousBean {
+ public String foo(Integer num) {
+ return "foo:" + num;
+ }
+
+ public String bar(Double num) {
+ return "bar:" + num;
+ }
+ }
+}