[
https://issues.apache.org/jira/browse/CAMEL-6481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13692850#comment-13692850
]
Emmanuel Loyon edited comment on CAMEL-6481 at 6/25/13 2:04 PM:
----------------------------------------------------------------
I understand that I can't get the length of the array because it's a property
of it.
So I converted it to an ArrayList in order to be able to get the size of it.
This is a method and it exists.
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="timer:test?repeatCount=1"/>
<setBody>
<groovy>[[2, "Chaine_avec_des_underscores", 12, "c"], ["d4", "e5",
"f6"]]</groovy>
</setBody>
<split>
<simple>${body}</simple>
<log message="${body[1]}"/>
<setHeader headerName="splittedColumn1" >
<simple
resultType="java.util.ArrayList">${body[1].split("_")}</simple>
</setHeader>
<log message="${header.splittedColumn1}"/>
<setHeader headerName="splittedColumn2">
<simple>header.splittedColumn1.size</simple>
</setHeader>
<log message="${header.splittedColumn2}"/>
</split>
</route>
</routes>
{code}
But I get the following error:
{noformat}
2013-06-25 10:29:44,069 [Camel (51-camel-4) thread #3 - timer://test] ERROR
aluminium.camel.logger - Failed delivery for (MessageId:
ID-pc-rd34-59514-1372148971632-1-1 on ExchangeId:
ID-pc-rd34-59514-1372148971632-1-3). Exhausted after delivery attempt: 1
caught: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed
to invoke method: .size on null due to:
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: size on null due to: org.apache.camel.RuntimeExchangeException:
IllegalAccessException occurred invoking method: public int
java.util.Arrays$ArrayList.size() using arguments: [] on the exchange:
Exchange[Message: [2, Chaine_avec_des_underscores, 12, c]]
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: .size on null due to:
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: size on null due to: org.apache.camel.RuntimeExchangeException:
IllegalAccessException occurred invoking method: public int
java.util.Arrays$ArrayList.size() using arguments: [] on the exchange:
Exchange[Message: [2, Chaine_avec_des_underscores, 12, c]]
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:117)
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:132)
at
org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:121)
{noformat}
Which seems to be caused by:
{noformat}
Caused by: java.lang.IllegalAccessException: Class
org.apache.camel.component.bean.MethodInfo can not access a member of class
java.util.Arrays$ArrayList with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown
Source)
at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:391)
... 86 more
{noformat}
It might be related to CAMEL-6260 but I see it is fixed in version 2.11.0 which
is the one I'm using.
was (Author: eloyon):
I understand that I can't get the length of the array because it's a
property of it.
So I converted it to an ArrayList in order to be able to get the size of it.
This is a method and it exists.
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://camel.apache.org/schema/spring"
xmlns:u="http://www.systar.com/aluminium/camel-util">
<route>
<from uri="timer:test?repeatCount=1"/>
<setBody>
<groovy>[[2, "Chaine_avec_des_underscores", 12, "c"], ["d4", "e5",
"f6"]]</groovy>
</setBody>
<split>
<simple>${body}</simple>
<log message="${body[1]}"/>
<setHeader headerName="splittedColumn1" >
<simple
resultType="java.util.ArrayList">${body[1].split("_")}</simple>
</setHeader>
<log message="${header.splittedColumn1}"/>
<setHeader headerName="splittedColumn2">
<simple>header.splittedColumn1.size</simple>
</setHeader>
<log message="${header.splittedColumn2}"/>
</split>
</route>
</routes>
{code}
But I get the following error:
{noformat}
2013-06-25 10:29:44,069 [Camel (51-camel-4) thread #3 - timer://test] ERROR
aluminium.camel.logger - Failed delivery for (MessageId:
ID-pc-rd34-59514-1372148971632-1-1 on ExchangeId:
ID-pc-rd34-59514-1372148971632-1-3). Exhausted after delivery attempt: 1
caught: org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed
to invoke method: .size on null due to:
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: size on null due to: org.apache.camel.RuntimeExchangeException:
IllegalAccessException occurred invoking method: public int
java.util.Arrays$ArrayList.size() using arguments: [] on the exchange:
Exchange[Message: [2, Chaine_avec_des_underscores, 12, c]]
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: .size on null due to:
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke
method: size on null due to: org.apache.camel.RuntimeExchangeException:
IllegalAccessException occurred invoking method: public int
java.util.Arrays$ArrayList.size() using arguments: [] on the exchange:
Exchange[Message: [2, Chaine_avec_des_underscores, 12, c]]
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:117)
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:132)
at
org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:121)
{noformat}
Which seems to be caused by:
{noformat}
Caused by: java.lang.IllegalAccessException: Class
org.apache.camel.component.bean.MethodInfo can not access a member of class
java.util.Arrays$ArrayList with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown
Source)
at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:391)
... 86 more
{noformat}
It might be related to CAMEL-6260 but I see it is fixed in version 2.11.0 which
is the one I'm using.
> Can't access to length of Array (java) from simple language
> -----------------------------------------------------------
>
> Key: CAMEL-6481
> URL: https://issues.apache.org/jira/browse/CAMEL-6481
> Project: Camel
> Issue Type: Improvement
> Components: camel-core
> Affects Versions: 2.11.0
> Reporter: Jérôme Decq
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 2.11.1, 2.12.0
>
>
> Cannot evaluate length on java.lang.String[] in simple
> I suspect this is because this is part of the language itself. But still, why
> not?
> h3. repro step
> run this:
> {noformat}
> ?xml version="1.0" encoding="UTF-8"?>
> <routes xmlns="http://camel.apache.org/schema/spring" >
> <route>
> <from uri="timer:test?repeatCount=1"/>
> <setBody>
> <groovy>[[2, "Chaine_avec_des_underscores", 12, "c"], ["d4",
> "e5", "f6"]]</groovy>
> </setBody>
> <split>
> <simple>${body}</simple>
> <setHeader headerName="splittedColumn1">
> <simple>${body[1].split("_")}</simple>
> </setHeader>
> <log message="${header.splittedColumn1.length}"/>
> </split>
> </route>
> </routes>
> {noformat}
> errors with:
> {noformat}
> org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
> invoke method: .length on null due to:
> org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
> invoke method: length on null due to:
> org.apache.camel.component.bean.MethodNotFoundException: Method with name:
> length not found on bean: [Ljava.lang.String;@33318365 of type:
> [Ljava.lang.String;. Exchange[Message: [d4, e5, f6]]{noformat}
--
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