private void updateState() { if (state == State.CLOSED || !executed) { return; } if (nonDaemonHeirsCount == 0) { if (heirs.isEmpty()) { if (state == State.TRYING) { if (failure == null) { state = State.FINALIZING; execute(); } else { state = State.CATCHING; execute(); } } else if (state == State.CATCHING) { state = State.FINALIZING; execute(); } else if (state == State.FINALIZING) { assert state != State.CLOSED; state = State.CLOSED; if (failure == null) { parent.remove(this); } else { parent.fail(this, failure); } } else { throw new IllegalStateException("Unknown state " + state); } } else { if (failure == null) { daemondCausedCancellation = true; } cancelHeirs(); } } }