commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chen (Jira)" <j...@apache.org>
Subject [jira] [Updated] (COLLECTIONS-732) Got an UnsupportedOperationException when using MultiValuedMap.MapIterator().setValue()
Date Tue, 05 Nov 2019 13:00:00 GMT

     [ https://issues.apache.org/jira/browse/COLLECTIONS-732?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Chen updated COLLECTIONS-732:
-----------------------------
    Description: 
copy from https://issues.apache.org/jira/browse/COLLECTIONS-663
{code:java}
    public void testSetValueMapIterator(){
        final ListValuedMap<K, V> listMap = makeObject();
        List<V> listA = listMap.get((K) "A");
        listA.addAll(0, Arrays.asList((V) "W", (V) "X", (V) "F"));
        List<V> listB = listMap.get((K) "B");
        listB.addAll(0, Arrays.asList((V) "Q", (V) "Q", (V) "L"));
        assertEquals("{A=[W, X, F], B=[Q, Q, L]}", listMap.toString());        for(MapIterator<K,
V> iterator = listMap.mapIterator(); iterator.hasNext(); ){
            iterator.next();
            V value = iterator.getValue();
            if(value == "F"){
                iterator.setValue((V) "B");
            }
        }
        assertEquals("{A=[W, X, B], B=[Q, Q, L]}", listMap.toString());
    } 
{code}
It throws an UnsupportedOperationException when altering mapIterator().setValue()。
I found UnsupportedOperationException is thrown in the code of setValue。So,if setValue
method is not supported,the Javadoc should comment it。


  was:
copy from https://issues.apache.org/jira/browse/COLLECTIONS-663
{code:java}
    public void testSetValueMapIterator(){
        final ListValuedMap<K, V> listMap = makeObject();
        List<V> listA = listMap.get((K) "A");
        listA.addAll(0, Arrays.asList((V) "W", (V) "X", (V) "F"));
        List<V> listB = listMap.get((K) "B");
        listB.addAll(0, Arrays.asList((V) "Q", (V) "Q", (V) "L"));
        assertEquals("{A=[W, X, F], B=[Q, Q, L]}", listMap.toString());        for(MapIterator<K,
V> iterator = listMap.mapIterator(); iterator.hasNext(); ){
            iterator.next();
            V value = iterator.getValue();
            if(value == "F"){
                iterator.setValue((V) "B");
            }
        }
        assertEquals("{A=[W, X, B], B=[Q, Q, L]}", listMap.toString());
    } throws a UnsupportedOperationException when altering mapIterato setValue。{code}
The issue is that the code throws UnsupportedOperationException  in setValue。So,if setValue
method is not supported,the Javadoc should comment。


> Got an UnsupportedOperationException when using MultiValuedMap.MapIterator().setValue()
> ---------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-732
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-732
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Map
>            Reporter: Chen
>            Priority: Major
>
> copy from https://issues.apache.org/jira/browse/COLLECTIONS-663
> {code:java}
>     public void testSetValueMapIterator(){
>         final ListValuedMap<K, V> listMap = makeObject();
>         List<V> listA = listMap.get((K) "A");
>         listA.addAll(0, Arrays.asList((V) "W", (V) "X", (V) "F"));
>         List<V> listB = listMap.get((K) "B");
>         listB.addAll(0, Arrays.asList((V) "Q", (V) "Q", (V) "L"));
>         assertEquals("{A=[W, X, F], B=[Q, Q, L]}", listMap.toString());        for(MapIterator<K,
V> iterator = listMap.mapIterator(); iterator.hasNext(); ){
>             iterator.next();
>             V value = iterator.getValue();
>             if(value == "F"){
>                 iterator.setValue((V) "B");
>             }
>         }
>         assertEquals("{A=[W, X, B], B=[Q, Q, L]}", listMap.toString());
>     } 
> {code}
> It throws an UnsupportedOperationException when altering mapIterator().setValue()。
> I found UnsupportedOperationException is thrown in the code of setValue。So,if setValue
method is not supported,the Javadoc should comment it。



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Mime
View raw message