cancel
Showing results for 
Search instead for 
Did you mean: 

NullPointerException in SpringBeanFactoryProxyMap.containsKey

sergey_p
Champ in-the-making
Champ in-the-making
Hello,

I'm experiencing a NPE when adding script task to a process in a Spring web application.
The process itself is pretty complicated, but runs w/o any issues except for this.

Here's the stacktrace:


25 Aug 2015 17:43:48 DEBUG org.activiti.engine.impl.interceptor.CommandContext  - Error while closing command context
java.lang.NullPointerException
   at org.activiti.engine.impl.cfg.SpringBeanFactoryProxyMap.containsKey(SpringBeanFactoryProxyMap.java:46)
   at org.activiti.engine.impl.scripting.BeansResolverFactory.containsKey(BeansResolverFactory.java:30)
   at org.activiti.engine.impl.scripting.ScriptBindings.get(ScriptBindings.java:71)
   at javax.script.SimpleScriptContext.getAttribute(SimpleScriptContext.java:167)
   at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:107)
   at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:87)
   at org.activiti.engine.impl.scripting.ScriptingEngines.evaluate(ScriptingEngines.java:73)
   at org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior.execute(ScriptTaskActivityBehavior.java:62)
   at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:60)
   at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:96)


Here's where it fails:


  public boolean containsKey(Object key) {
    if ( (key==null) || (!String.class.isAssignableFrom(key.getClass())) ) {
      return false;
    }
    return beanFactory.containsBean((String) key);
  }


Apparently, beanFactory is null.

Here's the excerpt from process configuration:


    …
    <startEvent id="sid-D8FCB27D-46BC-4401-9F0C-147F4103AFB8" activiti:initiator="initiator"></startEvent>
    <sequenceFlow id="sid-E963054E-9A90-4F05-8F6E-27D44150B2FA" sourceRef="sid-D8FCB27D-46BC-4401-9F0C-147F4103AFB8" targetRef="testScript"></sequenceFlow>
    <scriptTask id="testScript" name="TestScript" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script><![CDATA[out:print "Testing script task\n";
testVar = "test";]]></script>
    </scriptTask>
    <sequenceFlow id="sid-7D68D05F-1CF7-4000-8E67-FE5526B6DD21" sourceRef="testScript" targetRef="fillVariables"></sequenceFlow>
    …


The same pocess definition runs normally if I import it into activiti-explorer.

The problem is that I have no idea how to start debugging this, — can someone please give me a couple pointers on where to start?
I have a couple of task listeners configured through parse handlers, — might that be the issue?
2 REPLIES 2

vasile_dirla
Star Contributor
Star Contributor
Hi,
is it possible to you to deliver a unit test which will show this behaviour ?
(this will be useful to see your config, and also will be easier to investigate)

About the NPE issue.. it seems the spring's applicationContext is not injected for some reasons.

usually this listener in your web.xml is necessary to do it, unless you are using the servlet style.

<code>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</code>

If you will provide a unit test, it will be precious.

sergey_p
Champ in-the-making
Champ in-the-making
To anyone facing the same issue, I figured it out: turns out, I haven't provided Activiti w/Spring context. It's precisely the application context that's acting as bean factory in this case, which is null, unless provided to process engine. Here's the fix:

<java>
@Configuration
public class ActivitiConfig implements ApplicationContextAware {
    …
    @Bean
    public ProcessEngine processEngine() throws Exception {
        ProcessEngineFactoryBean factory = new ProcessEngineFactoryBean();
        factory.setApplicationContext(ac); // provide Spring app. context to process engine
        factory.setProcessEngineConfiguration(
                (ProcessEngineConfigurationImpl) activitiEngineConfiguration());
        return factory.getObject();
    }
    …
}
</java>