This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.14.x by this push:
     new 345ef9258f9a CAMEL-22978: Better parameter matching in 
PropertyBindingSupport
345ef9258f9a is described below

commit 345ef9258f9af7723bba69a56110352f30d2b0e2
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Feb 12 13:29:53 2026 +0100

    CAMEL-22978: Better parameter matching in PropertyBindingSupport
---
 .../PropertyBindingSupportConstructorTest.java     | 65 ++++++++++++++++++++++
 .../camel/support/PropertyBindingSupport.java      | 48 +++++++++-------
 2 files changed, 92 insertions(+), 21 deletions(-)

diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
index fe11ffb5a74f..29b509cbf9a2 100644
--- 
a/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/PropertyBindingSupportConstructorTest.java
@@ -144,6 +144,28 @@ public class PropertyBindingSupportConstructorTest {
         context.stop();
     }
 
+    @Test
+    public void testConstructorQuotedInteger() {
+        CamelContext context = new DefaultCamelContext();
+
+        context.start();
+
+        MyAppWithInteger target = new MyAppWithInteger();
+
+        PropertyBindingSupport.build()
+                .withCamelContext(context)
+                .withTarget(target)
+                .withProperty("name", "Donald")
+                .withProperty("age",
+                        "#class:" + MyInteger.class.getName() + "('42')")
+                .withRemoveParameters(false).bind();
+
+        assertEquals("Donald", target.getName());
+        assertEquals(42, target.getAge().getAge());
+
+        context.stop();
+    }
+
     public static class MyApp {
 
         private String name;
@@ -188,10 +210,36 @@ public class PropertyBindingSupportConstructorTest {
         }
     }
 
+    public static class MyAppWithInteger {
+
+        private String name;
+        private MyInteger age;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public MyInteger getAge() {
+            return age;
+        }
+
+        public void setAge(MyInteger age) {
+            this.age = age;
+        }
+    }
+
     public static class MyConfig {
 
         private final boolean enabled;
 
+        public MyConfig(String enabled) {
+            throw new UnsupportedOperationException("Should not be called");
+        }
+
         public MyConfig(boolean enabled) {
             this.enabled = enabled;
         }
@@ -201,4 +249,21 @@ public class PropertyBindingSupportConstructorTest {
         }
     }
 
+    public static class MyInteger {
+
+        private final int age;
+
+        public MyInteger(String age) {
+            this.age = -1;
+        }
+
+        public MyInteger(int age) {
+            this.age = age;
+        }
+
+        public int getAge() {
+            return age;
+        }
+    }
+
 }
diff --git 
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
 
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 6ccbd8ce8f27..fa8d07ca3608 100644
--- 
a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ 
b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -48,6 +48,7 @@ import org.apache.camel.util.StringHelper;
 import org.apache.camel.util.StringQuoteHelper;
 
 import static org.apache.camel.util.ObjectHelper.isNotEmpty;
+import static org.apache.camel.util.StringHelper.isQuoted;
 import static org.apache.camel.util.StringHelper.removeLeadingAndEndingQuotes;
 import static org.apache.camel.util.StringHelper.startsWithIgnoreCase;
 
@@ -1327,7 +1328,7 @@ public final class PropertyBindingSupport {
                 Class<?> parameterType = getValidParameterType(camelContext, 
parameter);
                 Class<?> expectedType = ctr.getParameterTypes()[i];
 
-                if (parameterType != null && expectedType != null) {
+                if (parameterType != null) {
                     // skip java.lang.Object type, when we have multiple 
possible methods we want to avoid it if possible
                     if (Object.class.equals(expectedType)) {
                         fallbackCandidate = ctr;
@@ -1453,7 +1454,7 @@ public final class PropertyBindingSupport {
                 Class<?> parameterType = getValidParameterType(camelContext, 
parameter);
                 Class<?> expectedType = method.getParameterTypes()[i];
 
-                if (parameterType != null && expectedType != null) {
+                if (parameterType != null) {
                     // skip java.lang.Object type, when we have multiple 
possible methods we want to avoid it if possible
                     if (Object.class.equals(expectedType)) {
                         fallbackCandidate = method;
@@ -1494,16 +1495,16 @@ public final class PropertyBindingSupport {
         // trim value
         value = value.trim();
 
-        // single quoted is valid
-        if (value.startsWith("'") && value.endsWith("'")) {
-            String unquoted = value.substring(1, value.length() - 1);
-            return isBooleanValue(unquoted) ? Boolean.class : String.class;
-        }
-
-        // double quoted is valid
-        if (value.startsWith("\"") && value.endsWith("\"")) {
-            String unquoted = value.substring(1, value.length() - 1);
-            return isBooleanValue(unquoted) ? Boolean.class : String.class;
+        // parameters may be wrapped in single/double-quoted, so special check
+        if (isQuoted(value)) {
+            String unquoted = removeLeadingAndEndingQuotes(value);
+            // try same logic again but unquoted (look for special types)
+            Class<?> answer = getValidParameterType(camelContext, unquoted);
+            if (answer == null) {
+                // okay then it's a string
+                answer = String.class;
+            }
+            return answer;
         }
 
         // true or false is valid (boolean)
@@ -1531,18 +1532,11 @@ public final class PropertyBindingSupport {
         }
 
         // numeric is valid
-        boolean numeric = true;
-        for (char ch : value.toCharArray()) {
-            if (!Character.isDigit(ch)) {
-                numeric = false;
-                break;
-            }
-        }
-        if (numeric) {
+        if (isNumericValue(value)) {
             return Number.class;
         }
 
-        // not valid
+        // unknown type
         return null;
     }
 
@@ -1550,6 +1544,18 @@ public final class PropertyBindingSupport {
         return "true".equalsIgnoreCase(value) || 
"false".equalsIgnoreCase(value);
     }
 
+    private static boolean isNumericValue(String value) {
+        // numeric is valid
+        boolean numeric = true;
+        for (char ch : value.toCharArray()) {
+            if (!Character.isDigit(ch)) {
+                numeric = false;
+                break;
+            }
+        }
+        return numeric;
+    }
+
     private static boolean isParameterMatchingType(Class<?> parameterType, 
Class<?> expectedType) {
         if (Number.class.equals(parameterType)) {
             // number should match long/int/etc.

Reply via email to