Hi all,

I was just debugging an issue that I am not sure if it is a bug or not.
Lets assume the following to classes:

package test.dto;
abstract class A {
  private String privA;

  public String getPrivA() {
    return privA;
  }
}

package test.dto;
public class B extends A {
  private String privB;

  public String getPrivB() {
    return privB;
  }
}

Now I have an Object of type B in a message body and have the following
simple expression:

.log(LoggingLevel.INFO, "BODY B: ${body.privB}")
.log(LoggingLevel.INFO, "BODY A: ${body.privA}")

Now this works fine for the first log line but for the second one it
produces the following NPE:

###snip
org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to
invoke method: privA on null due to: java.lang.NullPointerException
at
org.apache.camel.language.bean.BeanExpression.invokeOgnlMethod(BeanExpression.java:302)
BeanExpression.java:302
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:114)
BeanExpression.java:114
at
org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:135)
BeanExpression.java:135
at
org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:128)
ExpressionDefinition.java:128
at
org.apache.camel.model.language.ExpressionDefinition.evaluate(ExpressionDefinition.java:120)
ExpressionDefinition.java:120
at
org.apache.camel.builder.ExpressionBuilder$40.evaluate(ExpressionBuilder.java:1004)
ExpressionBuilder.java:1004
[...]
Caused by: java.lang.NullPointerException
at java.base/java.util.Objects.requireNonNull(Objects.java:221)
at java.base/java.util.Arrays$ArrayList.<init>(Arrays.java:4323)
at java.base/java.util.Arrays.asList(Arrays.java:4310)
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:483)
MethodInfo.java:483
[...]
###snap

Important: this NPE is actually an IllegalAccessException thrown
in org.apache.camel.component.bean.MethodInfo.class:481 but is then
swallowed by an NPE in line 483 because "arguments" is actually null.

Question is: shouldn't OGNL transform "body.privA" into "body.getPrivA()"
and then access the public accessor getPrivA()? The same thing works ok for
access to "body.privB" and that member is also private but has a public
accessor getPrivB()?

My Camel version is 2.24.2. So is this a bug or am I missing the forest for
the trees?

Thanks!

Reply via email to