ignite-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Venkata (Jira)" <j...@apache.org>
Subject [jira] [Commented] (IGNITE-12240) ReadOnlyCollectionView2X fails on iterator.next
Date Wed, 16 Oct 2019 07:24:00 GMT

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

Venkata commented on IGNITE-12240:
----------------------------------

[~kcheng.mvp] i am new to ignite, i looked at the issue, and thought following can be the
fix. let me know if you think the same.
{code:java}
// code placeholder
private Iterator<? extends T> it1 = c1.iterator();
private Iterator<? extends T> it2 = c2.iterator(); 
@Override 
public T next() {
                return it1 != null ? it1.next() : it2.next();
}{code}
Here it1 will not be null as c1.iterator() will give a valid reference. So in the scenario
it is giving that exception. the fix would be to check if the iterator hasNext() and then
return the element.
{code:java}

public T next()  { 
   if ( null == it1 && null == it2) 
       return null;     
   if ( it1.hasNext()) {  
       return it1.next(); 
   } 
   else if (it2.hasNext()) { 
       return it2.Next(); 
   } 
   else { 
       return null; 
   }  
}
{code}

> ReadOnlyCollectionView2X fails on iterator.next
> -----------------------------------------------
>
>                 Key: IGNITE-12240
>                 URL: https://issues.apache.org/jira/browse/IGNITE-12240
>             Project: Ignite
>          Issue Type: Bug
>    Affects Versions: 2.7.6
>            Reporter: Nikolay Izhikov
>            Assignee: kcheng.mvp
>            Priority: Major
>              Labels: newbie
>
> Simple reproducer below will throw {{NoSuchElementException}}.
> Iterator only works if one call {{hasNext}} before {{next}}.
> {code:java}
>     /** */
>     @Test
>     public void testReadOnlyCollection() throws Exception {
>         Collection<String> c1 = Collections.emptyList();
>         Collection<String> c2 = Arrays.asList("1");
>         ReadOnlyCollectionView2X<String> view = new ReadOnlyCollectionView2X<>(c1,
c2);
>         assertEquals("1", view.iterator().next());
>     }
> {code}



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

Mime
View raw message