From bae840ebf77f95c0e3ed4be8144866f7844554a0 Mon Sep 17 00:00:00 2001 From: vanitasvitae Date: Fri, 30 Jun 2017 15:36:02 +0200 Subject: [PATCH] Enforce jingle s5b transport invariants. There can only either be one info element or multiple candidates, but not both. Enforced this in the JingleS5BTransportBuilder --- .../jingle_s5b/elements/JingleS5BTransport.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/elements/JingleS5BTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/elements/JingleS5BTransport.java index 3d1a3759d..a70b5d9a6 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/elements/JingleS5BTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transports/jingle_s5b/elements/JingleS5BTransport.java @@ -93,7 +93,7 @@ public class JingleS5BTransport extends JingleContentTransport { private String streamId; private String dstAddr; private Bytestream.Mode mode; - private ArrayList candidates = new ArrayList<>(); + private final ArrayList candidates = new ArrayList<>(); private JingleContentTransportInfo info; public Builder setStreamId(String sid) { @@ -112,11 +112,22 @@ public class JingleS5BTransport extends JingleContentTransport { } public Builder addTransportCandidate(JingleS5BTransportCandidate candidate) { + if (info != null) { + throw new IllegalStateException("Builder has already an info set. " + + "The transport can only have either an info or transport candidates, not both."); + } this.candidates.add(candidate); return this; } public Builder setTransportInfo(JingleContentTransportInfo info) { + if (!candidates.isEmpty()) { + throw new IllegalStateException("Builder has already at least one candidate set. " + + "The transport can only have either an info or transport candidates, not both."); + } + if (this.info != null) { + throw new IllegalStateException("Builder has already an info set."); + } this.info = info; return this; }