AnsweredAssumed Answered

BusinessProcessScoped beans in conversation scope cause NPE

Question asked by naag on Aug 13, 2012
Latest reply on Aug 14, 2012 by naag
Hi all,

I've got one more question regarding CDI behaviour in Activiti 5.10. We've got a @BusinessProcessScoped bean that we use in JSF forms. Especially this bean is used on the process start form before the process is started, so we want the bean to be associated to the conversation scope. So via


<f:event type="preRenderView" listener="#{startProcessBean.preStart()}" />

we start a new conversation on the JSF form that uses our @BusinessProcessScoped bean and then we start the process via BusinessProcess.startProcessByKey(). This used to work in Activiti 5.9, but in 5.10, we get a NPE. This is the stacktrace:


Caused by: java.lang.NullPointerException
   at org.activiti.cdi.impl.context.DefaultContextAssociationManager.getExecutionId(DefaultContextAssociationManager.java:184) [activiti-cdi-5.10.jar:]
   at org.activiti.cdi.BusinessProcess.isAssociated(BusinessProcess.java:260) [activiti-cdi-5.10.jar:]
   at org.activiti.cdi.impl.context.BusinessProcessContext.get(BusinessProcessContext.java:99) [activiti-cdi-5.10.jar:]
   at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
   at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
   at foo.bar.SomeBusinessBean$Proxy$_$$_WeldClientProxy.getCostCenter(SomeBusinessBean$Proxy$_$$_WeldClientProxy.java) [business-bean-0.0.2.jar:]
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_31]
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_31]
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_31]
   at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_31]
   at javax.el.BeanELResolver.getValue(BeanELResolver.java:302) [jboss-el-api_2.2_spec-1.0.0.Final.jar:1.0.0.Final]
   at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
   at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
   at org.apache.el.parser.AstValue.getValue(AstValue.java:169) [jbossweb-7.0.13.Final.jar:]
   at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) [jbossweb-7.0.13.Final.jar:]
   at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
   at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) [jsf-impl-2.1.7-jbossorg-2.jar:]
   … 83 more

The failing code is this:


public class DefaultContextAssociationManager implements ContextAssociationManager, Serializable {
  // …
  @Override
  public String getExecutionId() {
    return getExecution().getId();
  }
  // …
}

And this change fixed it for me, but I'm not 100% sure if it's the right solution to this issue.


public class DefaultContextAssociationManager implements ContextAssociationManager, Serializable {
  // …
  @Override
  public String getExecutionId() {
    Execution execution = getExecution();
   if (execution != null) {
     return execution.getId();
   } else {
     return null;
   }
  }
  // …
}

What do you think?

Thanks a lot!
Peter

Outcomes