You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by 李家宏 <jh...@gmail.com> on 2014/03/06 15:28:43 UTC

CustomStreamGrouping: IndexOutOfBoundsException

hi, all
i'am using CustomStreamGrouping with very simple mod selection. it thrown
IndexOutOfBoundsException. From the trace below:

Caused by: java.lang.IndexOutOfBoundsException: null
at clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106)
~[clojure-1.4.0.jar:na]
at clojure.lang.PersistentVector.nth(PersistentVector.java:110)
~[clojure-1.4.0.jar:na]
at clojure.lang.APersistentVector.get(APersistentVector.java:167)
~[clojure-1.4.0.jar:na]
at bolts.PingPongGrouping.chooseTasks(PingPongGrouping.java:37)
~[stormjar.jar:na]

We locate the problem to the CustomStreamGrouping.chooseTasks() function
which looks like:

    @Override
    public List<Integer> chooseTasks(int i, List<Object> values) {
        ArrayList<Integer> boltIds = new ArrayList<Integer>();
        if (values.size() > 0) {
            int hashcode = values.get(0).hashCode();
            int index = hashcode % _targetTasks.size();
            *boltIds.add( _targetTasks.get(index));    // here is the
problem*
        } else {
            boltIds.add( _targetTasks.get(0));
        }
        return boltIds;
    }

    @Override
    public void prepare(WorkerTopologyContext context, GlobalStreamId
streamId, List<Integer> targetTasks) {
        this._targetTasks = targetTasks;
    }

How can it be out of bounds ?

Regards


-- 

======================================================

Gvain

Email: jh.li.em@gmail.com

Re: 回复: CustomStreamGrouping: IndexOutOfBoundsException

Posted by 李家宏 <jh...@gmail.com>.
Hi, there

As Kang Xiao indicated, the problem is the int hashcode overflow and index
is a negative value.
I compare CustomStreamGrouping with fieldsGrouping. In fieldsGrouping, it
computing the hashcode of the grouping fields list: ArrayList<Object>
values. Here is the code:

   public int hashCode() {
        int hashCode = 1;
        for (E e : this)
            hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
        return hashCode;
   }

I am wondering why this works fine? Won't the hashCode overflow this way?

Regards


2014-03-07 8:53 GMT+08:00 肖康(Kang Xiao) <kx...@gmail.com>:

> It maybe that hashcode and index is less than zero. You can add debug log
> to print the two vars to verify.
>
> --
> Best Regards!
> 肖康(Kang Xiao)
>
> 在 2014年3月6日星期四,22:51,James Xu 写道:
>
> What is _targetTasks is empty?
>
> On 2014年3月6日, at 下午10:28, 李家宏 <jh...@gmail.com> wrote:
>
> hi, all
> i'am using CustomStreamGrouping with very simple mod selection. it thrown
> IndexOutOfBoundsException. From the trace below:
>
> Caused by: java.lang.IndexOutOfBoundsException: null
>  at clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106)
> ~[clojure-1.4.0.jar:na]
>  at clojure.lang.PersistentVector.nth(PersistentVector.java:110)
> ~[clojure-1.4.0.jar:na]
> at clojure.lang.APersistentVector.get(APersistentVector.java:167)
> ~[clojure-1.4.0.jar:na]
>  at bolts.PingPongGrouping.chooseTasks(PingPongGrouping.java:37)
> ~[stormjar.jar:na]
>
> We locate the problem to the CustomStreamGrouping.chooseTasks() function
> which looks like:
>
>     @Override
>     public List<Integer> chooseTasks(int i, List<Object> values) {
>         ArrayList<Integer> boltIds = new ArrayList<Integer>();
>         if (values.size() > 0) {
>             int hashcode = values.get(0).hashCode();
>             int index = hashcode % _targetTasks.size();
>             *boltIds.add( _targetTasks.get(index));    // here is the
> problem*
>         } else {
>             boltIds.add( _targetTasks.get(0));
>         }
>         return boltIds;
>     }
>
>     @Override
>     public void prepare(WorkerTopologyContext context, GlobalStreamId
> streamId, List<Integer> targetTasks) {
>         this._targetTasks = targetTasks;
>     }
>
> How can it be out of bounds ?
>
> Regards
>
>
> --
>
> ======================================================
>
> Gvain
>
> Email: jh.li.em@gmail.com
>
>
>
>


-- 

======================================================

Gvain

Email: jh.li.em@gmail.com

回复: CustomStreamGrouping: IndexOutOfBoundsException

Posted by "肖康(Kang Xiao)" <kx...@gmail.com>.
It maybe that hashcode and index is less than zero. You can add debug log to print the two vars to verify.  

--  
Best Regards!
肖康(Kang Xiao)


在 2014年3月6日星期四,22:51,James Xu 写道:

> What is _targetTasks is empty?
>  
> On 2014年3月6日, at 下午10:28, 李家宏 <jh.li.em@gmail.com (mailto:jh.li.em@gmail.com)> wrote:
> > hi, all
> > i'am using CustomStreamGrouping with very simple mod selection. it thrown IndexOutOfBoundsException. From the trace below:
> >  
> > Caused by: java.lang.IndexOutOfBoundsException: null  
> > at clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106) ~[clojure-1.4.0.jar:na]
> > at clojure.lang.PersistentVector.nth(PersistentVector.java:110) ~[clojure-1.4.0.jar:na]
> > at clojure.lang.APersistentVector.get(APersistentVector.java:167) ~[clojure-1.4.0.jar:na]
> > at bolts.PingPongGrouping.chooseTasks(PingPongGrouping.java:37) ~[stormjar.jar:na]
> >  
> >  
> > We locate the problem to the CustomStreamGrouping.chooseTasks() function which looks like:
> >  
> >     @Override
> >     public List<Integer> chooseTasks(int i, List<Object> values) {
> >         ArrayList<Integer> boltIds = new ArrayList<Integer>();
> >         if (values.size() > 0) {
> >             int hashcode = values.get(0).hashCode();
> >             int index = hashcode % _targetTasks.size();
> >             boltIds.add( _targetTasks.get(index));    // here is the problem
> >         } else {
> >             boltIds.add( _targetTasks.get(0));
> >         }
> >         return boltIds;
> >     }
> >  
> >     @Override
> >     public void prepare(WorkerTopologyContext context, GlobalStreamId streamId, List<Integer> targetTasks) {
> >         this._targetTasks = targetTasks;
> >     }
> >  
> > How can it be out of bounds ?
> >  
> > Regards
> >  
> > --  
> > ======================================================
> > Gvain
> > Email: jh.li.em@gmail.com (mailto:jh.li.em@gmail.com)
> >  
> >  
> >  
>  
>  
>  


回复: CustomStreamGrouping: IndexOutOfBoundsException

Posted by "肖康(Kang Xiao)" <kx...@gmail.com>.
It maybe that hashcode and index is less than zero. You can add debug log to print the two vars to verify.  

--  
Best Regards!
肖康(Kang Xiao)


在 2014年3月6日星期四,22:51,James Xu 写道:

> What is _targetTasks is empty?
>  
> On 2014年3月6日, at 下午10:28, 李家宏 <jh.li.em@gmail.com (mailto:jh.li.em@gmail.com)> wrote:
> > hi, all
> > i'am using CustomStreamGrouping with very simple mod selection. it thrown IndexOutOfBoundsException. From the trace below:
> >  
> > Caused by: java.lang.IndexOutOfBoundsException: null  
> > at clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106) ~[clojure-1.4.0.jar:na]
> > at clojure.lang.PersistentVector.nth(PersistentVector.java:110) ~[clojure-1.4.0.jar:na]
> > at clojure.lang.APersistentVector.get(APersistentVector.java:167) ~[clojure-1.4.0.jar:na]
> > at bolts.PingPongGrouping.chooseTasks(PingPongGrouping.java:37) ~[stormjar.jar:na]
> >  
> >  
> > We locate the problem to the CustomStreamGrouping.chooseTasks() function which looks like:
> >  
> >     @Override
> >     public List<Integer> chooseTasks(int i, List<Object> values) {
> >         ArrayList<Integer> boltIds = new ArrayList<Integer>();
> >         if (values.size() > 0) {
> >             int hashcode = values.get(0).hashCode();
> >             int index = hashcode % _targetTasks.size();
> >             boltIds.add( _targetTasks.get(index));    // here is the problem
> >         } else {
> >             boltIds.add( _targetTasks.get(0));
> >         }
> >         return boltIds;
> >     }
> >  
> >     @Override
> >     public void prepare(WorkerTopologyContext context, GlobalStreamId streamId, List<Integer> targetTasks) {
> >         this._targetTasks = targetTasks;
> >     }
> >  
> > How can it be out of bounds ?
> >  
> > Regards
> >  
> > --  
> > ======================================================
> > Gvain
> > Email: jh.li.em@gmail.com (mailto:jh.li.em@gmail.com)
> >  
> >  
> >  
>  
>  
>  


Re: CustomStreamGrouping: IndexOutOfBoundsException

Posted by James Xu <xu...@gmail.com>.
What is _targetTasks is empty?

On 2014年3月6日, at 下午10:28, 李家宏 <jh...@gmail.com> wrote:

> hi, all
> i'am using CustomStreamGrouping with very simple mod selection. it thrown IndexOutOfBoundsException. From the trace below:
> 
> Caused by: java.lang.IndexOutOfBoundsException: null
> 	at clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106) ~[clojure-1.4.0.jar:na]
> 	at clojure.lang.PersistentVector.nth(PersistentVector.java:110) ~[clojure-1.4.0.jar:na]
> 	at clojure.lang.APersistentVector.get(APersistentVector.java:167) ~[clojure-1.4.0.jar:na]
> 	at bolts.PingPongGrouping.chooseTasks(PingPongGrouping.java:37) ~[stormjar.jar:na]
> 
> We locate the problem to the CustomStreamGrouping.chooseTasks() function which looks like:
> 
>     @Override
>     public List<Integer> chooseTasks(int i, List<Object> values) {
>         ArrayList<Integer> boltIds = new ArrayList<Integer>();
>         if (values.size() > 0) {
>             int hashcode = values.get(0).hashCode();
>             int index = hashcode % _targetTasks.size();
>             boltIds.add( _targetTasks.get(index));    // here is the problem
>         } else {
>             boltIds.add( _targetTasks.get(0));
>         }
>         return boltIds;
>     }
> 
>     @Override
>     public void prepare(WorkerTopologyContext context, GlobalStreamId streamId, List<Integer> targetTasks) {
>         this._targetTasks = targetTasks;
>     }
> 
> How can it be out of bounds ?
> 
> Regards
> 
> 
> -- 
> ======================================================
> 
> Gvain
> 
> Email: jh.li.em@gmail.com
> 


Re: CustomStreamGrouping: IndexOutOfBoundsException

Posted by James Xu <xu...@gmail.com>.
What is _targetTasks is empty?

On 2014年3月6日, at 下午10:28, 李家宏 <jh...@gmail.com> wrote:

> hi, all
> i'am using CustomStreamGrouping with very simple mod selection. it thrown IndexOutOfBoundsException. From the trace below:
> 
> Caused by: java.lang.IndexOutOfBoundsException: null
> 	at clojure.lang.PersistentVector.arrayFor(PersistentVector.java:106) ~[clojure-1.4.0.jar:na]
> 	at clojure.lang.PersistentVector.nth(PersistentVector.java:110) ~[clojure-1.4.0.jar:na]
> 	at clojure.lang.APersistentVector.get(APersistentVector.java:167) ~[clojure-1.4.0.jar:na]
> 	at bolts.PingPongGrouping.chooseTasks(PingPongGrouping.java:37) ~[stormjar.jar:na]
> 
> We locate the problem to the CustomStreamGrouping.chooseTasks() function which looks like:
> 
>     @Override
>     public List<Integer> chooseTasks(int i, List<Object> values) {
>         ArrayList<Integer> boltIds = new ArrayList<Integer>();
>         if (values.size() > 0) {
>             int hashcode = values.get(0).hashCode();
>             int index = hashcode % _targetTasks.size();
>             boltIds.add( _targetTasks.get(index));    // here is the problem
>         } else {
>             boltIds.add( _targetTasks.get(0));
>         }
>         return boltIds;
>     }
> 
>     @Override
>     public void prepare(WorkerTopologyContext context, GlobalStreamId streamId, List<Integer> targetTasks) {
>         this._targetTasks = targetTasks;
>     }
> 
> How can it be out of bounds ?
> 
> Regards
> 
> 
> -- 
> ======================================================
> 
> Gvain
> 
> Email: jh.li.em@gmail.com
>