Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public int bitIndex(final String key, final int offsetInBits, final int lengthIn
k = 0;
} else {
k = key.charAt(index1);
if (k == 0) {
throw new IllegalArgumentException("Character '\\u0000' is not supported in the key.");
}
}

if (other == null || index2 >= endIndex2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -427,6 +428,24 @@ public void testPrefixMapClearUsingRemove() {
assertEquals(Arrays.asList(2, 3, 7, 1), new ArrayList<>(trie.values()));
}

public void testNullTerminatedKey() {
// COLLECTIONS-714
PatriciaTrie<Integer> trie = new PatriciaTrie<>();
try {
trie.put("x\u0000", 1);
} catch (IllegalArgumentException e) {
// expected
}

Map<String, Integer> map = new HashMap<>();
map.put("x\u0000", 1);
try {
trie = new PatriciaTrie<>(map);
} catch (IllegalArgumentException e) {
// expected
}
}

//-----------------------------------------------------------------------

@Override
Expand Down