[jira] Created: (CAMEL-3) Issue with getHeader("", Boolean.class)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (CAMEL-3) Issue with getHeader("", Boolean.class)

JIRA jira@apache.org
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.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (CAMEL-3) Issue with getHeader("", Boolean.class)

JIRA jira@apache.org

     [ 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.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-3) Issue with getHeader("", Boolean.class)

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

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

Hiram Chirino updated CAMEL-3:
------------------------------

    Fix Version/s: 1.0

> Issue with getHeader("", Boolean.class)
> ---------------------------------------
>
>                 Key: CAMEL-3
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-3
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: Noah Nordrum
>            Assignee: James Strachan
>            Priority: Critical
>             Fix For: 1.0
>
>
>     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.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CAMEL-3) Issue with getHeader("", Boolean.class)

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

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

Hiram Chirino updated CAMEL-3:
------------------------------

    Description:
{code:java}
    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);
    }
{code}
throws NPE on the isDebug = ... line.

  was:
    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.


> Issue with getHeader("", Boolean.class)
> ---------------------------------------
>
>                 Key: CAMEL-3
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-3
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>            Reporter: Noah Nordrum
>            Assignee: James Strachan
>            Priority: Critical
>             Fix For: 1.0
>
>
> {code:java}
>     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);
>     }
> {code}
> 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.