[ 
https://issues.apache.org/jira/browse/CAMEL-6781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Franz Forsthofer updated CAMEL-6781:
------------------------------------

    Fix Version/s: 2.13.0
                   2.12.2
                   2.11.3

> IntrospectionSupport.setProperty ClassCastException if you have overloaded 
> methods
> ----------------------------------------------------------------------------------
>
>                 Key: CAMEL-6781
>                 URL: https://issues.apache.org/jira/browse/CAMEL-6781
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.11.1, 2.12.0
>            Reporter: Franz Forsthofer
>             Fix For: 2.11.3, 2.12.2, 2.13.0
>
>         Attachments: 0001-ClassCastException-in-setProperties.patch
>
>
> If you use DefaultComponent.setProperties(config, parameters) with a config 
> object having overloaded methods you can get the following Exception:
> org.apache.camel.NoSuchBeanException: Found bean: myExpression in JNDI 
> Context: javax.naming.InitialContext@7f597bc4 of type: 
> org.apache.camel.builder.ExpressionBuilder$31 expected type was: class 
> java.lang.String
>       at 
> org.apache.camel.impl.JndiRegistry.lookupByNameAndType(JndiRegistry.java:60)
>       at 
> org.apache.camel.impl.PropertyPlaceholderDelegateRegistry.lookupByNameAndType(PropertyPlaceholderDelegateRegistry.java:63)
>       at 
> org.apache.camel.util.CamelContextHelper.lookup(CamelContextHelper.java:121)
>       at 
> org.apache.camel.util.IntrospectionSupport.setProperty(IntrospectionSupport.java:499)
>       at 
> org.apache.camel.util.EndpointHelper.setReferenceProperties(EndpointHelper.java:271)
>       at 
> org.apache.camel.impl.DefaultComponent.setProperties(DefaultComponent.java:263)
>       at 
> org.apache.camel.impl.DefaultComponentReferencePropertiesTest$MyComponent.createEndpoint(DefaultComponentReferencePropertiesTest.java:94)
>       at 
> org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:120)
>       at 
> org.apache.camel.impl.DefaultComponentReferencePropertiesTest.testCallExpressionSetter(DefaultComponentReferencePropertiesTest.java:152)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.lang.reflect.Method.invoke(Method.java:606)
>       at junit.framework.TestCase.runTest(TestCase.java:176)
>       at junit.framework.TestCase.runBare(TestCase.java:141)
>       at org.apache.camel.TestSupport.runBare(TestSupport.java:58)
>       at junit.framework.TestResult$1.protect(TestResult.java:122)
>       at junit.framework.TestResult.runProtected(TestResult.java:142)
>       at junit.framework.TestResult.run(TestResult.java:125)
>       at junit.framework.TestCase.run(TestCase.java:129)
>       at junit.framework.TestSuite.runTest(TestSuite.java:255)
>       at junit.framework.TestSuite.run(TestSuite.java:250)
>       at 
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
>       at 
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>       at 
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>       at 
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: java.lang.ClassCastException: Cannot cast 
> org.apache.camel.builder.ExpressionBuilder$31 to java.lang.String
>       at java.lang.Class.cast(Class.java:3084)
>       at 
> org.apache.camel.impl.JndiRegistry.lookupByNameAndType(JndiRegistry.java:56)
>       ... 28 more
> The exception does not occur always it dpends on the order of the methods 
> with the same name. In IntrospectionSupport.setProperty you find
> {code}
>  setters = findSetterMethods(clazz, name, value, allowBuilderPattern);
> ...
>   Class<?> parameterType = setter.getParameterTypes()[0];
>             Object ref = value;
>             // try and lookup the reference based on the method
>             if (context != null && refName != null && ref == null) {
>                 ref = CamelContextHelper.lookup(context, 
> refName.replaceAll("#", ""), parameterType);
> {code}
> If by chance the first setter method has a paramterType which fits to the 
> referenced bean then you will not get the exception. But if the first setter 
> method has a parameterType which does not fit to the referenced bean then you 
> will get the exception.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to