You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dmitriyC300 <dm...@gmail.com> on 2016/10/13 16:33:15 UTC

simple language nullsafe expression fails on empty array

I may have found a limitation w/ simple language on the 1st index of an empty
array with a nullsafe expression.  Making sure list.size() > 0 in
BeanExpression line 384 should address this use case.  

I'm happy to submit a pull request with a tweak & unit test case if that's
helpful.  

public void testOGNLBodyEmptyList() throws Exception {
        Map<String, List&lt;String>> map = new HashMap<String,
List&lt;String>>();
        map.put("list", new ArrayList<String>());
         
        exchange.getIn().setBody(map);

        assertExpression("${in.body?.get('list')[0].toString}", null);
    }

org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
invoke method: ?.get('list')[0].toString on java.util.HashMap due to:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:120)
	at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:138)
	at
org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:126)
	at
org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:118)
	at
org.apache.camel.builder.ExpressionBuilder$40.evaluate(ExpressionBuilder.java:993)
	at
org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
	at org.apache.camel.TestSupport.assertExpression(TestSupport.java:255)
	at
org.apache.camel.ContextTestSupport.assertExpression(ContextTestSupport.java:314)
	at
org.apache.camel.LanguageTestSupport.assertExpression(LanguageTestSupport.java:62)
	at
org.apache.camel.LanguageTestSupport.assertExpression(LanguageTestSupport.java:69)
	at
org.apache.camel.language.simple.SimpleTest.testOGNLBodyEmptyList(SimpleTest.java:267)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	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:252)
	at junit.framework.TestSuite.run(TestSuite.java:247)
	at
org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at
org.apache.camel.language.bean.BeanExpression$OgnlInvokeProcessor.lookupResult(BeanExpression.java:385)
	at
org.apache.camel.language.bean.BeanExpression$OgnlInvokeProcessor.process(BeanExpression.java:334)
	at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:114)
	... 30 more

Dmitriy



--
View this message in context: http://camel.465427.n5.nabble.com/simple-language-nullsafe-expression-fails-on-empty-array-tp5788737.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: simple language nullsafe expression fails on empty array

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Yeah sure we love contributions
http://camel.apache.org/contributing

On Thu, Oct 13, 2016 at 6:33 PM, dmitriyC300 <dm...@gmail.com> wrote:
> I may have found a limitation w/ simple language on the 1st index of an empty
> array with a nullsafe expression.  Making sure list.size() > 0 in
> BeanExpression line 384 should address this use case.
>
> I'm happy to submit a pull request with a tweak & unit test case if that's
> helpful.
>
> public void testOGNLBodyEmptyList() throws Exception {
>         Map<String, List&lt;String>> map = new HashMap<String,
> List&lt;String>>();
>         map.put("list", new ArrayList<String>());
>
>         exchange.getIn().setBody(map);
>
>         assertExpression("${in.body?.get('list')[0].toString}", null);
>     }
>
> org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
> invoke method: ?.get('list')[0].toString on java.util.HashMap due to:
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>         at
> org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:120)
>         at
> org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:138)
>         at
> org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:126)
>         at
> org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:118)
>         at
> org.apache.camel.builder.ExpressionBuilder$40.evaluate(ExpressionBuilder.java:993)
>         at
> org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36)
>         at org.apache.camel.TestSupport.assertExpression(TestSupport.java:255)
>         at
> org.apache.camel.ContextTestSupport.assertExpression(ContextTestSupport.java:314)
>         at
> org.apache.camel.LanguageTestSupport.assertExpression(LanguageTestSupport.java:62)
>         at
> org.apache.camel.LanguageTestSupport.assertExpression(LanguageTestSupport.java:69)
>         at
> org.apache.camel.language.simple.SimpleTest.testOGNLBodyEmptyList(SimpleTest.java:267)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:497)
>         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:252)
>         at junit.framework.TestSuite.run(TestSuite.java:247)
>         at
> org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
>         at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
>         at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
> Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
>         at java.util.ArrayList.rangeCheck(ArrayList.java:653)
>         at java.util.ArrayList.get(ArrayList.java:429)
>         at
> org.apache.camel.language.bean.BeanExpression$OgnlInvokeProcessor.lookupResult(BeanExpression.java:385)
>         at
> org.apache.camel.language.bean.BeanExpression$OgnlInvokeProcessor.process(BeanExpression.java:334)
>         at
> org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:114)
>         ... 30 more
>
> Dmitriy
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/simple-language-nullsafe-expression-fails-on-empty-array-tp5788737.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2