Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E27201019E for ; Tue, 24 Sep 2013 12:00:44 +0000 (UTC) Received: (qmail 40259 invoked by uid 500); 24 Sep 2013 12:00:18 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 40220 invoked by uid 500); 24 Sep 2013 12:00:16 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 40119 invoked by uid 99); 24 Sep 2013 12:00:09 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Sep 2013 12:00:09 +0000 Date: Tue, 24 Sep 2013 12:00:09 +0000 (UTC) From: "Franz Forsthofer (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (CAMEL-6781) IntrospectionSupport.setProperty ClassCastException if you have overloaded methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-6781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Franz Forsthofer updated CAMEL-6781: ------------------------------------ Description: 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. was: 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 ferenced bean then you will get the exception. > 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 > 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 is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira