Skip to content

Commit 166af8e

Browse files
committed
toMessage Ensure version unique collection
Ensure AbstractMessage toMessage is a unique collection of versions as per the OTRv3 specification by using a LinkedHashSet as the initial container, copied to a concrete List for QueryMessage passing.
1 parent aac20b1 commit 166af8e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/net/java/otr4j/io/SerializationUtils.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.nio.charset.Charset;
1616
import java.security.PublicKey;
1717
import java.util.ArrayList;
18+
import java.util.LinkedHashSet;
1819
import java.util.List;
1920
import java.util.Vector;
2021
import java.util.regex.Matcher;
@@ -292,7 +293,8 @@ public static AbstractMessage toMessage(String s) throws IOException {
292293
|| contentType == SerializationConstants.HEAD_QUERY_Q) {
293294
// Query tag found.
294295

295-
List<Integer> versions = new Vector<Integer>();
296+
// LinkedHashSet ensures that each item is unique, as required by the OTRv3 Specification.
297+
LinkedHashSet<Integer> versions = new LinkedHashSet<Integer>();
296298
String versionString = null;
297299
if (SerializationConstants.HEAD_QUERY_Q == contentType) {
298300
versions.add(OTRv.ONE);
@@ -312,7 +314,8 @@ public static AbstractMessage toMessage(String s) throws IOException {
312314
versions.add(Integer.parseInt(String
313315
.valueOf((char) c)));
314316
}
315-
QueryMessage query = new QueryMessage(versions);
317+
// Create a concrete Type from the Abstract List for QueryMessage, passing in our unique collection.
318+
QueryMessage query = new QueryMessage(new ArrayList<Integer>(versions));
316319
return query;
317320
} else if (idxHead == 0 && contentType == SerializationConstants.HEAD_ENCODED) {
318321
// Data message found.

0 commit comments

Comments
 (0)