This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.20.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.20.x by this push: new bde8a71d582 [CAMEL-19075] camel-bean. Incorrect choice of overloaded method with several arguments, if one of them has brackets. (#9383) bde8a71d582 is described below commit bde8a71d5828e626013b822071705927310d6b68 Author: artemse <artemofic...@gmail.com> AuthorDate: Thu Feb 23 18:06:47 2023 +0300 [CAMEL-19075] camel-bean. Incorrect choice of overloaded method with several arguments, if one of them has brackets. (#9383) * [CAMEL-19075] camel-bean. Incorrect choice of overloaded method with several arguments, if one of them has brackets. * [CAMEL-19075] fix checkstyle error, added missing file header * [CAMEL-19075] test class of bean processor moved to camel-core module --- components/camel-bean/pom.xml | 1 - .../org/apache/camel/component/bean/BeanInfo.java | 2 +- ...ProcessorOverloadedMethodsWithBracketsTest.java | 62 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/components/camel-bean/pom.xml b/components/camel-bean/pom.xml index d45e5287136..87d949fe1b6 100644 --- a/components/camel-bean/pom.xml +++ b/components/camel-bean/pom.xml @@ -51,6 +51,5 @@ <version>${mockito-version}</version> <scope>test</scope> </dependency> - </dependencies> </project> 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 1c1c8ba4397..24e2e9c6ce5 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 @@ -1088,7 +1088,7 @@ public class BeanInfo { } // match qualifier types which is used to select among overloaded methods - String types = StringHelper.between(methodName, "(", ")"); + String types = StringHelper.betweenOuterPair(methodName, '(', ')'); if (org.apache.camel.util.ObjectHelper.isNotEmpty(types)) { // we must qualify based on types to match method String[] parameters = StringQuoteHelper.splitSafeQuote(types, ','); diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/BeanProcessorOverloadedMethodsWithBracketsTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/BeanProcessorOverloadedMethodsWithBracketsTest.java new file mode 100644 index 00000000000..ee94c989d1e --- /dev/null +++ b/core/camel-core/src/test/java/org/apache/camel/processor/BeanProcessorOverloadedMethodsWithBracketsTest.java @@ -0,0 +1,62 @@ +/* + * 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.processor; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BeanProcessorOverloadedMethodsWithBracketsTest extends ContextTestSupport { + + private final String strArgWithBrackets = ")(string_with_brackets()))())"; + + @Test + public void testOverloadedMethodWithBracketsParams() { + template.sendBody("direct:start", null); + MockEndpoint mock = getMockEndpoint("mock:result"); + String receivedExchangeBody = mock.getExchanges().get(0).getMessage().getBody(String.class); + assertEquals(new MyOverloadedClass().myMethod(strArgWithBrackets, strArgWithBrackets), receivedExchangeBody); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("direct:start") + .bean(MyOverloadedClass.class, "myMethod('" + strArgWithBrackets + "', '" + strArgWithBrackets + "')") + .to("mock:result"); + } + }; + } + + public static class MyOverloadedClass { + public String myMethod() { + return ""; + } + + public String myMethod(String str) { + return str; + } + + public String myMethod(String str1, String str2) { + return str1 + str2; + } + } +}