You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2016/08/04 17:33:20 UTC
[jira] [Resolved] (COLLECTIONS-586) PatriciaTrie prefixMap clear
throws NullPointerException
[ https://issues.apache.org/jira/browse/COLLECTIONS-586?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory resolved COLLECTIONS-586.
--------------------------------------
Resolution: Fixed
Please verify and close. This closes #18.
> PatriciaTrie prefixMap clear throws NullPointerException
> --------------------------------------------------------
>
> Key: COLLECTIONS-586
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-586
> Project: Commons Collections
> Issue Type: Bug
> Affects Versions: 4.1
> Reporter: Shailender Bathula
>
> Clearing all entries of a prefixMap returned by PatriciaTrie using the {{clear}} method throws a NullPointerException. The workaround of removing each entry using the {{remove}} method seems to work.
> Here are the test cases for the bug and the workaround:
> {code:java}
> public class PatriciaTrieTest {
> private Trie<String, Integer> trie;
> @Before
> public void setUp() {
> trie = new PatriciaTrie<Integer>();
> trie.put("Anna", 1);
> trie.put("Anael", 2);
> trie.put("Analu", 3);
> trie.put("Andreas", 4);
> trie.put("Andrea", 5);
> trie.put("Andres", 6);
> trie.put("Anatole", 7);
> }
> @Test
> public void testPrefixMapClear() {
> SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
> assertEquals(new HashSet<>(Arrays.asList("Andrea", "Andreas", "Andres")), prefixMap.keySet());
> assertEquals(Arrays.asList(5, 4, 6), new ArrayList<>(prefixMap.values()));
> prefixMap.clear();
> assertTrue(prefixMap.keySet().isEmpty());
> assertTrue(prefixMap.values().isEmpty());
> assertEquals(new HashSet<>(Arrays.asList("Anael", "Analu", "Anatole", "Anna")), trie.keySet());
> assertEquals(Arrays.asList(2, 3, 7, 1), new ArrayList<>(trie.values()));
> }
> @Test
> public void testPrefixMapClearUsingRemove() {
> SortedMap<String, Integer> prefixMap = trie.prefixMap("And");
> assertEquals(new HashSet<>(Arrays.asList("Andrea", "Andreas", "Andres")), prefixMap.keySet());
> assertEquals(Arrays.asList(5, 4, 6), new ArrayList<>(prefixMap.values()));
> Set<String> keys = new HashSet<String>(prefixMap.keySet());
> for (final String key : keys) {
> prefixMap.remove(key);
> }
> assertTrue(prefixMap.keySet().isEmpty());
> assertTrue(prefixMap.values().isEmpty());
> assertEquals(new HashSet<>(Arrays.asList("Anael", "Analu", "Anatole", "Anna")), trie.keySet());
> assertEquals(Arrays.asList(2, 3, 7, 1), new ArrayList<>(trie.values()));
> }
> }
> {code}
> The stacktrace of the NullPointerException thrown by the {{testPrefixMapClear}} test case is:
> {noformat}
> java.lang.NullPointerException
> at org.apache.commons.collections4.trie.AbstractPatriciaTrie$PrefixRangeEntrySet$EntryIterator.remove(AbstractPatriciaTrie.java:2370)
> at java.util.AbstractCollection.clear(AbstractCollection.java:432)
> at java.util.AbstractMap.clear(AbstractMap.java:288)
> at PatriciaTrieTest.testPrefixMapClear(PatriciaTrieTest.java:39)
> {noformat}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)