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 Thu, 04 Aug 2016 16:00:23 GMT

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

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

GitHub user marko-bekhta opened a pull request:

    https://github.com/apache/commons-collections/pull/18

    COLLECTIONS-586 PatriciaTrie prefixMap clear throws NullPointerException

    added unit tests for the case mentioned in the issue and overrode clear method so it is
not throwing exceptions

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/marko-bekhta/commons-collections trunk

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-collections/pull/18.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #18
    
----
commit 3627b954830acbe45ea08e9e1be31738ee759422
Author: marko.bekhta <markob@prykladna.lviv.ua>
Date:   2016-08-04T15:58:18Z

    COLLECTIONS-586 PatriciaTrie prefixMap clear throws NullPointerException
    
    added unit tests for the case mentioned in the issue and overrode clear method so it is
not throwing exceptions

----


> 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)

Mime
View raw message