You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Makoto YUI <yu...@gmail.com> on 2008/02/01 13:19:27 UTC

Re: mina and jdk6u4

I have the same problem to you. 
I'm using the latest snapshot (mina-core-2.0.0-M1-20080124.103130-116.jar).

| java.lang.ArrayIndexOutOfBoundsException
| at
org.apache.mina.util.CircularQueue.shrinkIfNeeded(CircularQueue.java:233)

This problem caused when newLen is less than the length of
System.arraycopy().

| Object[] tmp = new Object[newLen];
| ..   
|            if (first < last) {
|                System.arraycopy(items, first, tmp, 0, last - first);      
* bug
|            } else {
|                System.arraycopy(items, first, tmp, 0, oldLen - first);   *
bug
|                System.arraycopy(items, 0, tmp, oldLen - first, last);    *
bug
|            }

It seems to be preferred to use java.util.LinkedList instead of custom
CircularQueue 
for messageQueue(s) in
AbstractProtocolEncoderOutput/AbstractProtocolDecoderOutput.

Thanks,

Makoto YUI
-- 
View this message in context: http://www.nabble.com/mina-and-jdk6u4-tp14922204s16868p15225610.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: mina and jdk6u4

Posted by "이희승 (Trustin Lee)" <tr...@gmail.com>.
2008-02-01 (금), 13:57 +0100, Emmanuel Lecharny 쓰시길:
> Makoto YUI wrote:
> > I have the same problem to you. 
> > I'm using the latest snapshot (mina-core-2.0.0-M1-20080124.103130-116.jar).
> >
> > | java.lang.ArrayIndexOutOfBoundsException
> > | at
> > org.apache.mina.util.CircularQueue.shrinkIfNeeded(CircularQueue.java:233)
> >
> > This problem caused when newLen is less than the length of
> > System.arraycopy().
> >
> > | Object[] tmp = new Object[newLen];
> > | ..   
> > |            if (first < last) {
> > |                System.arraycopy(items, first, tmp, 0, last - first);      
> > * bug
> > |            } else {
> > |                System.arraycopy(items, first, tmp, 0, oldLen - first);   *
> > bug
> > |                System.arraycopy(items, 0, tmp, oldLen - first, last);    *
> > bug
> > |            }
> >
> > It seems to be preferred to use java.util.LinkedList instead of custom
> > CircularQueue 
> > for messageQueue(s) in
> > AbstractProtocolEncoderOutput/AbstractProtocolDecoderOutput.
> >
> > Thanks,
> >
> > Makoto YUI
> >   
> I don't think that it's a problem to use our own brewed CircularQueue ...
> 
> I looked at the code, and I'm a little bit annoyed that there is 
> absolutely no comment at all. There is a clear bug somewhere, as you got 
> a java.lang.ArrayIndexOutOfBoundsException (and many thanks for having 
> posting this mail, btw !!!), but without a knowledge about what is doing 
> this class, it's really difficult to find a fix in 2 minutes. This 
> should not be the case...
> 
> Btw, there is no test cases either...

I wrote that evil code hehe. :)

There's test case for CircularQueue in 1.x branch, but it was removed
from the trunk when I replace it with LinkedList.  After then, I
realized the CircularQueue implementation performs better than
LinkedList, so I resurrected it.  However, I forgot to resurrect the
test case together.  Will take care of this when I get back home.
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: ArrayIndexOutOfBoundsException in CircularQueue.

Posted by Makoto YUI <yu...@gmail.com>.
Hi Trustin,

> Thanks for the report.  I have been extremely busy with reorganizing
> my workstation due to some crash recently. 

That's too bad. 

> CircularQueue performs better than LinkedQueue according to my
> previous benchmark.  There's something that's very close to
> CircularQueue in Java 6, but we need to keep MINA working on Java 5.

I suspect the CicularQueue that you mentioned in this line is ArrayDeque 
since ArrayBlockingQueue supported from Java 5 is bounded and optimized for
concurrent uses.

Since ArrayDeque supported at Java 6 is released as public-domain software, 
thus it is a considerable option to replace your CircularQueue with it. 

It's a fairly good implementation except that it does not have shrinking
feature, I think.
http://g.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166x/ArrayDeque.java?revision=1.2&view=markup


Thanks, 
Makoto YUI
-- 
View this message in context: http://www.nabble.com/mina-and-jdk6u4-tp14922204s16868p15251727.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: ArrayIndexOutOfBoundsException in CircularQueue.

Posted by Trustin Lee <tr...@gmail.com>.
Hi Yui,

Thanks for the report.  I have been extremely busy with reorganizing
my workstation due to some crash recently.  Let me take a look into
the problem soon...

CircularQueue performs better than LinkedQueue according to my
previous benchmark.  There's something that's very close to
CircularQueue in Java 6, but we need to keep MINA working on Java 5.

Thanks,
Trustin

On Feb 2, 2008 7:07 PM, Makoto YUI <yu...@gmail.com> wrote:
>
> Hi,
>
> With replacing CircularQueue with LinkedQueue, my task is working fine.
>
> BTW, I have reviewed CircularQueue class.
>
> Is not CircularQueue#increaseSize() wrong?
>
> | private void increaseSize() {
> |  last = (last + 1) & mask;
> |  full = first == last; // this check condition is insufficient.
> | }
>
> This full flag affect shrinkIfNeeded() via size().
>
> Moreover, both of isEmpty() and remove(int) seem strange.
>
> e.g.,
> |    public boolean isEmpty() {
> |        return (first == last) && !full;  // should return (first == last)
> |    }
>
> Makoto
> --
> View this message in context: http://www.nabble.com/mina-and-jdk6u4-tp14922204s16868p15241380.html
>
> Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
>
>



-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: ArrayIndexOutOfBoundsException in CircularQueue.

Posted by Makoto YUI <yu...@gmail.com>.
Hi, 

With replacing CircularQueue with LinkedQueue, my task is working fine.

BTW, I have reviewed CircularQueue class.

Is not CircularQueue#increaseSize() wrong?

| private void increaseSize() {
|  last = (last + 1) & mask;
|  full = first == last; // this check condition is insufficient.
| }

This full flag affect shrinkIfNeeded() via size(). 

Moreover, both of isEmpty() and remove(int) seem strange.

e.g., 
|    public boolean isEmpty() {
|        return (first == last) && !full;  // should return (first == last)
|    }

Makoto
-- 
View this message in context: http://www.nabble.com/mina-and-jdk6u4-tp14922204s16868p15241380.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


ArrayIndexOutOfBoundsException in CircularQueue.

Posted by Makoto YUI <yu...@gmail.com>.
Thanks for fast responding.

| I looked at the code, and I'm a little bit annoyed that there is 
| absolutely no comment at all. There is a clear bug somewhere, as you got 
| a java.lang.ArrayIndexOutOfBoundsException (and many thanks for having 
| posting this mail, btw !!!), but without a knowledge about what is doing 
| this class, it's really difficult to find a fix in 2 minutes. This 
| should not be the case...

I just wanted to report where ArrayIndexOutOfBoundsException caused.
Bug might be somewhere else (at least) in the CircularQueue.

I agree that it needs more reviews than minutes.

BTW, the *unbounded* CircularQueue is used just as a FIFO "java.util.Queue" 
at least in AbstractProtocolEncoderOutput/AbstractProtocolDecoderOutput.
Then, the unbounded CircularQueue does Shrinking.

Why not use LinkedList as the Queue? Is there some performance related
reasons?
I could not find strong reason to use it.
# I will do this workaround since this exception is actually a blocker of my
task ;-( 

Makoto
-- 
View this message in context: http://www.nabble.com/mina-and-jdk6u4-tp14922204s16868p15227105.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.


Re: mina and jdk6u4

Posted by Emmanuel Lecharny <el...@gmail.com>.
Makoto YUI wrote:
> I have the same problem to you. 
> I'm using the latest snapshot (mina-core-2.0.0-M1-20080124.103130-116.jar).
>
> | java.lang.ArrayIndexOutOfBoundsException
> | at
> org.apache.mina.util.CircularQueue.shrinkIfNeeded(CircularQueue.java:233)
>
> This problem caused when newLen is less than the length of
> System.arraycopy().
>
> | Object[] tmp = new Object[newLen];
> | ..   
> |            if (first < last) {
> |                System.arraycopy(items, first, tmp, 0, last - first);      
> * bug
> |            } else {
> |                System.arraycopy(items, first, tmp, 0, oldLen - first);   *
> bug
> |                System.arraycopy(items, 0, tmp, oldLen - first, last);    *
> bug
> |            }
>
> It seems to be preferred to use java.util.LinkedList instead of custom
> CircularQueue 
> for messageQueue(s) in
> AbstractProtocolEncoderOutput/AbstractProtocolDecoderOutput.
>
> Thanks,
>
> Makoto YUI
>   
I don't think that it's a problem to use our own brewed CircularQueue ...

I looked at the code, and I'm a little bit annoyed that there is 
absolutely no comment at all. There is a clear bug somewhere, as you got 
a java.lang.ArrayIndexOutOfBoundsException (and many thanks for having 
posting this mail, btw !!!), but without a knowledge about what is doing 
this class, it's really difficult to find a fix in 2 minutes. This 
should not be the case...

Btw, there is no test cases either...

-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org