Fix possible NPE

- getState() now handles null better when checking
  running state when possibly going to return
  final state.
- Fixes #227
This commit is contained in:
Janne Valkealahti
2016-05-21 09:54:21 +01:00
parent 588eee751f
commit e9cb3af785
5 changed files with 233 additions and 4 deletions

View File

@@ -165,7 +165,7 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
public State<S,E> getState() {
// if we're complete assume we're stopped
// and state was stashed into lastState
if (isComplete()) {
if (lastState != null && isComplete()) {
return lastState;
} else {
return currentState;
@@ -388,11 +388,12 @@ public abstract class AbstractStateMachine<S, E> extends StateMachineObjectSuppo
@Override
public boolean isComplete() {
if (currentState == null) {
State<S, E> s = currentState;
if (s == null) {
return !isRunning();
} else {
return currentState != null && currentState.getPseudoState() != null
&& currentState.getPseudoState().getKind() == PseudoStateKind.END;
return s != null && s.getPseudoState() != null
&& s.getPseudoState().getKind() == PseudoStateKind.END;
}
}