AbstractStateMachine.acceptEvent 方法中的 NullPointerException 错误
NullPointerException error in AbstractStateMachine.acceptEvent method
下面是我的一个 class 项目,它使用 spring-statemachine-core-1.0.2.RELEASE-sources.jar,它实现了从一个的简单转换状态给另一个。它在 AbstractStateMachine.acceptEvent 方法中的 currentState 上引发空指针异常。欣赏help/thoughts。
java.lang.NullPointerException
在 org.springframework.statemachine.support.AbstractStateMachine.acceptEvent(AbstractStateMachine.java:591)
import java.util.Arrays;
import java.util.HashSet;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineBuilder;
import org.springframework.statemachine.config.StateMachineBuilder.Builder;
public class Processor {
public static void main(String[] args) throws Exception {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureStates()
.withStates()
.initial("INIT").end("END")
.states(new HashSet<String>(Arrays.asList("INIT","MIDDLE","END")));
builder.configureTransitions()
.withExternal()
.source("INIT").target("MIDDLE").event("START")
.and()
.withExternal()
.source("MIDDLE").target("END");
builder.configureConfiguration().withConfiguration().autoStartup(true);
StateMachine<String, String> stateMachine = builder.build();
stateMachine.start();
stateMachine.sendEvent("START");
stateMachine.stop();
}
}
是的,手动生成器机器没有默认 taskExecutor
。它已经在 master 和 1.0.x 分支中修复,但我们还没有发布 1.0.3。解决方法是手动设置:
builder
.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true);
下面是我的一个 class 项目,它使用 spring-statemachine-core-1.0.2.RELEASE-sources.jar,它实现了从一个的简单转换状态给另一个。它在 AbstractStateMachine.acceptEvent 方法中的 currentState 上引发空指针异常。欣赏help/thoughts。
java.lang.NullPointerException 在 org.springframework.statemachine.support.AbstractStateMachine.acceptEvent(AbstractStateMachine.java:591)
import java.util.Arrays;
import java.util.HashSet;
import org.springframework.statemachine.StateMachine;
import org.springframework.statemachine.config.StateMachineBuilder;
import org.springframework.statemachine.config.StateMachineBuilder.Builder;
public class Processor {
public static void main(String[] args) throws Exception {
Builder<String, String> builder = StateMachineBuilder.builder();
builder.configureStates()
.withStates()
.initial("INIT").end("END")
.states(new HashSet<String>(Arrays.asList("INIT","MIDDLE","END")));
builder.configureTransitions()
.withExternal()
.source("INIT").target("MIDDLE").event("START")
.and()
.withExternal()
.source("MIDDLE").target("END");
builder.configureConfiguration().withConfiguration().autoStartup(true);
StateMachine<String, String> stateMachine = builder.build();
stateMachine.start();
stateMachine.sendEvent("START");
stateMachine.stop();
}
}
是的,手动生成器机器没有默认 taskExecutor
。它已经在 master 和 1.0.x 分支中修复,但我们还没有发布 1.0.3。解决方法是手动设置:
builder
.configureConfiguration()
.withConfiguration()
.taskExecutor(new SyncTaskExecutor())
.autoStartup(true);