camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (CAMEL-3) Issue with getHeader("", Boolean.class)
Date Mon, 04 Jun 2007 10:09:33 GMT

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

James Strachan resolved CAMEL-3.
--------------------------------

    Resolution: Fixed

I've added a test case here

https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/Issue3Test.java

which is a minor refactor of your test case. (I switched to the direct: endpoint so that the
send is synchronous, so no need to sleep & the exception fails the test case - also I
used the handy base class for starting/stopping the context etc).

I got a valid stack trace BTW. I suspect the reason you didn't was a JVM thing (e.g. try running
with hotspot disabled maybe?).

Basically the issue was to do with Java 5's type coercion and not anything specific with Camel.


Boolean b = in.getHeader("foo", Boolean.class);

does work fine and returns null for an undefined property. However if you force it to be coerced
to a 'boolean' rather than 'Boolean') you get an NPE as the value is null (since there is
no header called "foo"). (The same is true when converting from Integer to int when the value
is null).

I've just patched the converter code so that if you do 

boolean b = in.getHeader("foo", boolean.class);

then it returns a valid value and does not throw an NPE. (i.e. it returns false for missing
headers).



> Issue with getHeader("", Boolean.class)
> ---------------------------------------
>
>                 Key: CAMEL-3
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-3
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: core
>            Reporter: Noah Nordrum
>            Assignee: James Strachan
>            Priority: Critical
>
>     public void testNPE() throws Exception {
>         final CamelContext camelContext = new DefaultCamelContext();
>         final String fromQueue = "queue:A";
>         camelContext.addRoutes(new RouteBuilder() {
>             public void configure() throws Exception {
>                 from(fromQueue).process(new Processor() {
>                     public void process(Exchange exchange) throws Exception {
>                         final Message in = exchange.getIn();
>                         assertNotNull("Message is Null", in);
>                         String isDebugString = in.getHeader("someproperty", String.class);
>                         assertNull(isDebugString);
>                         assertNotNull("Message is Null", in);
>                         boolean isDebug = in.getHeader("someproperty", Boolean.class);
>                         assertFalse(isDebug);
>                     }
>                 });
>             }
>         });
>         camelContext.start();
>         new CamelTemplate(camelContext).sendBody(fromQueue, "ha!");
>         Thread.sleep(5000L);
>     }
> throws NPE on the isDebug = ... line.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message