From 285c750e69c99a47afd8644221f7fbefb6c17f1d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 8 May 2020 18:36:52 +0200 Subject: [PATCH] throw IllegalStateException when trying to finish from a non terminal state --- .../xmpp/jingle/JingleRtpConnection.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java index 5bb0e7b60..ecf2aff32 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jingle/JingleRtpConnection.java @@ -58,6 +58,9 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web ); private static final long BUSY_TIME_OUT = 30; private static final List TERMINATED = Arrays.asList( + State.ACCEPTED, + State.REJECTED, + State.RETRACTED, State.TERMINATED_SUCCESS, State.TERMINATED_DECLINED_OR_BUSY, State.TERMINATED_CONNECTIVITY_ERROR, @@ -642,13 +645,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web } try { setupWebRTC(media, iceServers); - } catch (WebRTCWrapper.InitializationException e) { + } catch (final WebRTCWrapper.InitializationException e) { Log.d(Config.LOGTAG, id.account.getJid().asBareJid() + ": unable to initialize WebRTC"); webRTCWrapper.close(); //todo we haven’t actually initiated the session yet; so sending sessionTerminate makes no sense //todo either we don’t ring ever at all or maybe we should send a retract or something transitionOrThrow(State.TERMINATED_APPLICATION_FAILURE); - this.finish();; + this.finish(); return; } try { @@ -1142,9 +1145,13 @@ public class JingleRtpConnection extends AbstractJingleConnection implements Web } private void finish() { - this.cancelRingingTimeout(); - this.webRTCWrapper.verifyClosed(); - this.jingleConnectionManager.finishConnection(this); + if (isTerminated()) { + this.cancelRingingTimeout(); + this.webRTCWrapper.verifyClosed(); + this.jingleConnectionManager.finishConnection(this); + } else { + throw new IllegalStateException(String.format("Unable to call finish from %s", this.state)); + } } private void writeLogMessage(final State state) {