commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COLLECTIONS-586) PatriciaTrie prefixMap clear throws NullPointerException
Date Mon, 17 Jul 2017 18:23:00 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16090231#comment-16090231
] 

ASF GitHub Bot commented on COLLECTIONS-586:
--------------------------------------------

Github user asfgit closed the pull request at:

    https://github.com/apache/commons-collections/pull/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.4.14#64029)

Mime
View raw message