throw IllegalStateException when trying to finish from a non terminal state

This commit is contained in:
Daniel Gultsch 2020-05-08 18:36:52 +02:00
parent 350fc57d87
commit 285c750e69

View file

@ -58,6 +58,9 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
); );
private static final long BUSY_TIME_OUT = 30; private static final long BUSY_TIME_OUT = 30;
private static final List<State> TERMINATED = Arrays.asList( private static final List<State> TERMINATED = Arrays.asList(
State.ACCEPTED,
State.REJECTED,
State.RETRACTED,
State.TERMINATED_SUCCESS, State.TERMINATED_SUCCESS,
State.TERMINATED_DECLINED_OR_BUSY, State.TERMINATED_DECLINED_OR_BUSY,
State.TERMINATED_CONNECTIVITY_ERROR, State.TERMINATED_CONNECTIVITY_ERROR,
@ -642,13 +645,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
try { try {
setupWebRTC(media, iceServers); setupWebRTC(media, iceServers);
} catch (WebRTCWrapper.InitializationException e) { } catch (final WebRTCWrapper.InitializationException e) {
Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to initialize WebRTC"); Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to initialize WebRTC");
webRTCWrapper.close(); webRTCWrapper.close();
//todo we havent actually initiated the session yet; so sending sessionTerminate makes no sense //todo we havent actually initiated the session yet; so sending sessionTerminate makes no sense
//todo either we dont ring ever at all or maybe we should send a retract or something //todo either we dont ring ever at all or maybe we should send a retract or something
transitionOrThrow(State.TERMINATED_APPLICATION_FAILURE); transitionOrThrow(State.TERMINATED_APPLICATION_FAILURE);
this.finish();; this.finish();
return; return;
} }
try { try {
@ -1142,9 +1145,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web
} }
private void finish() { private void finish() {
if (isTerminated()) {
this.cancelRingingTimeout(); this.cancelRingingTimeout();
this.webRTCWrapper.verifyClosed(); this.webRTCWrapper.verifyClosed();
this.jingleConnectionManager.finishConnection(this); this.jingleConnectionManager.finishConnection(this);
} else {
throw new IllegalStateException(String.format("Unable to call finish from %s", this.state));
}
} }
private void writeLogMessage(final State state) { private void writeLogMessage(final State state) {