You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hans Orbaan <ha...@docdata.eu> on 2015/04/10 15:42:21 UTC

transformers not working after update to 2.15.1

Hi all,

I am trying to update to 2.15.1 from 2.14.2 and am running into some trouble.
We have a lot of transformers that extend an abstractTransformer class. That abstractTransformer implements a Transformer interface with a transform method.
The various implementations usually return an XML class that can be marshalled, but the interface specifies Object as return (also tried generics, same issue as below).
This used to work but now it returns a stacktrace:
java.lang.NullPointerException: null
                at org.apache.camel.component.bean.BeanInfo.chooseBestPossibleMethodInfo(BeanInfo.java:762) ~[camel-core-2.15.1.jar:2.15.1]
                at org.apache.camel.component.bean.BeanInfo.chooseMethodWithMatchingBody(BeanInfo.java:735) ~[camel-core-2.15.1.jar:2.15.1]
                at org.apache.camel.component.bean.BeanInfo.chooseMethod(BeanInfo.java:603) ~[camel-core-2.15.1.jar:2.15.1]
                at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:254) ~[camel-core-2.15.1.jar:2.15.1]
                at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:183) ~[camel-core-2.15.1.jar:2.15.1]
                at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:153) ~[camel-core-2.15.1.jar:2.15.1]

The camel code that throws the exception:

    private MethodInfo chooseBestPossibleMethodInfo(Exchange exchange, Collection<MethodInfo> operationList, Object body,
                                                    List<MethodInfo> possibles, List<MethodInfo> possiblesWithException,
                                                    List<MethodInfo> possibleWithCustomAnnotation)
                               ......
                               ......
            for (MethodInfo methodInfo : operationList) {
                // nullpointer bodyParameterType
                if (methodInfo.getBodyParameterType().isInstance(body)) {
                    return methodInfo;
                }

This doesn't happen when the transformerImp implements the interface and the abstractTransformer does not.
This also doesn't happen when the return class in the interface is the same as that of the implementation. Just no subclasses allowed.

Could you have a look at the test cases I have created to show the problem:

////// MyRoute.java
@Component
public class MyRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("file:///data/proj_test")
            .log("file read")
            .transform().method(TransformerImpl.class, "transform")
            .log("transformed")
            .end();
    }
}
////// TransformerImpl.java
public class TransformerImpl extends AbstractTransformer {

    @Override
    public String transform(Exchange exchange) {
        return getTest();
    }
}
////// AbstractTransformer.java
public abstract class AbstractTransformer implements Transformer {
    protected String getTest() {
        return "test";
    }
}
////// Transformer.java
public interface Transformer {

    Object transform(Exchange exchange) ;
}

------------- TEST 2 (abstract method, also fails in 2.14.2 ?) ------------
reuse MyRoute.java
reuse TransformerImpl.java
////// AbstractTransformer.java
public abstract class AbstractTransformer {
    public abstract Object transform(Exchange exchange);
    protected String getTest() {
        return "test";
    }
}
------------- TEST 3 (generics abstract) ------------
reuse MyRoute.java
////// TransformerImpl.java
public class TransformerImpl extends AbstractTransformer<String> {

    @Override
    public String transform(Exchange exchange) {
        return "test";
    }
}
////// AbstractTransformer.java
public abstract class AbstractTransformer<TYPE> {
    public abstract TYPE transform(Exchange exchange);
    protected String getTest() {
        return "test";
    }
}
------------- TEST 3 (generics to interface, works in 2.14.2, not 2.15.1) ------------
reuse MyRoute.java
////// TransformerImpl.java
public class TransformerImpl extends AbstractTransformer<String>  {

    @Override
    public String transform(Exchange exchange) {
        return "test";
    }
}
////// AbstractTransformer.java
public abstract class AbstractTransformer<TYPE> implements Transformer<TYPE>{
    protected String getTest() {
        return "test";
    }
}
////// Transformer.java
public interface Transformer<TYPE> {

    TYPE transform(Exchange exchange) ;
}

Is this a bug or some change that was meant to do this?

Thanks for any help you can provide.

Re: transformers not working after update to 2.15.1

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

I have logged a ticket about the NPE
https://issues.apache.org/jira/browse/CAMEL-8624

On Fri, Apr 10, 2015 at 3:42 PM, Hans Orbaan <ha...@docdata.eu> wrote:
> Hi all,
>
> I am trying to update to 2.15.1 from 2.14.2 and am running into some trouble.
> We have a lot of transformers that extend an abstractTransformer class. That abstractTransformer implements a Transformer interface with a transform method.
> The various implementations usually return an XML class that can be marshalled, but the interface specifies Object as return (also tried generics, same issue as below).
> This used to work but now it returns a stacktrace:
> java.lang.NullPointerException: null
>                 at org.apache.camel.component.bean.BeanInfo.chooseBestPossibleMethodInfo(BeanInfo.java:762) ~[camel-core-2.15.1.jar:2.15.1]
>                 at org.apache.camel.component.bean.BeanInfo.chooseMethodWithMatchingBody(BeanInfo.java:735) ~[camel-core-2.15.1.jar:2.15.1]
>                 at org.apache.camel.component.bean.BeanInfo.chooseMethod(BeanInfo.java:603) ~[camel-core-2.15.1.jar:2.15.1]
>                 at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:254) ~[camel-core-2.15.1.jar:2.15.1]
>                 at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.java:183) ~[camel-core-2.15.1.jar:2.15.1]
>                 at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:153) ~[camel-core-2.15.1.jar:2.15.1]
>
> The camel code that throws the exception:
>
>     private MethodInfo chooseBestPossibleMethodInfo(Exchange exchange, Collection<MethodInfo> operationList, Object body,
>                                                     List<MethodInfo> possibles, List<MethodInfo> possiblesWithException,
>                                                     List<MethodInfo> possibleWithCustomAnnotation)
>                                ......
>                                ......
>             for (MethodInfo methodInfo : operationList) {
>                 // nullpointer bodyParameterType
>                 if (methodInfo.getBodyParameterType().isInstance(body)) {
>                     return methodInfo;
>                 }
>
> This doesn't happen when the transformerImp implements the interface and the abstractTransformer does not.
> This also doesn't happen when the return class in the interface is the same as that of the implementation. Just no subclasses allowed.
>
> Could you have a look at the test cases I have created to show the problem:
>
> ////// MyRoute.java
> @Component
> public class MyRoute extends RouteBuilder {
>     @Override
>     public void configure() throws Exception {
>         from("file:///data/proj_test")
>             .log("file read")
>             .transform().method(TransformerImpl.class, "transform")
>             .log("transformed")
>             .end();
>     }
> }
> ////// TransformerImpl.java
> public class TransformerImpl extends AbstractTransformer {
>
>     @Override
>     public String transform(Exchange exchange) {
>         return getTest();
>     }
> }
> ////// AbstractTransformer.java
> public abstract class AbstractTransformer implements Transformer {
>     protected String getTest() {
>         return "test";
>     }
> }
> ////// Transformer.java
> public interface Transformer {
>
>     Object transform(Exchange exchange) ;
> }
>
> ------------- TEST 2 (abstract method, also fails in 2.14.2 ?) ------------
> reuse MyRoute.java
> reuse TransformerImpl.java
> ////// AbstractTransformer.java
> public abstract class AbstractTransformer {
>     public abstract Object transform(Exchange exchange);
>     protected String getTest() {
>         return "test";
>     }
> }
> ------------- TEST 3 (generics abstract) ------------
> reuse MyRoute.java
> ////// TransformerImpl.java
> public class TransformerImpl extends AbstractTransformer<String> {
>
>     @Override
>     public String transform(Exchange exchange) {
>         return "test";
>     }
> }
> ////// AbstractTransformer.java
> public abstract class AbstractTransformer<TYPE> {
>     public abstract TYPE transform(Exchange exchange);
>     protected String getTest() {
>         return "test";
>     }
> }
> ------------- TEST 3 (generics to interface, works in 2.14.2, not 2.15.1) ------------
> reuse MyRoute.java
> ////// TransformerImpl.java
> public class TransformerImpl extends AbstractTransformer<String>  {
>
>     @Override
>     public String transform(Exchange exchange) {
>         return "test";
>     }
> }
> ////// AbstractTransformer.java
> public abstract class AbstractTransformer<TYPE> implements Transformer<TYPE>{
>     protected String getTest() {
>         return "test";
>     }
> }
> ////// Transformer.java
> public interface Transformer<TYPE> {
>
>     TYPE transform(Exchange exchange) ;
> }
>
> Is this a bug or some change that was meant to do this?
>
> Thanks for any help you can provide.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/