• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

ArrayIndexOutOfBoundsException

Joined
Apr 25, 2010
Messages
479
Reaction score
49
My trade system was not working , I made some changes and it worked . But always when I confirm the trade is with 1 or 2 player I get this error. More does not affect anything in return, it just appears that message. I think my PacketReader is correct too.

Code:
java.lang.ArrayIndexOutOfBoundsException: 4
	at handling.mina.PacketReader.readDatatype(PacketReader.java:46)
	at handling.mina.PacketReader.readShort(PacketReader.java:54)
	at handling.channel.handler.PlayerInteractionHandler.PlayerInteraction(PlayerInteractionHandler.java:353)
	at handling.MapleServerHandler.handlePacket(MapleServerHandler.java:546)
	at handling.MapleServerHandler.messageReceived(MapleServerHandler.java:190)
	at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:570)
	at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
	at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
	at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
	at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flush(SimpleProtocolDecoderOutput.java:58)
	at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:180)
	at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
	at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
	at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
	at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:220)
	at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
	at java.lang.Thread.run(Unknown Source)

PlayerInteractionHandler.java:353

Code:
short bundles = slea.readShort();

PacketReader.java:54

Code:
    public short readShort() {
        return (short)readDatatype(2);
    }

PacketReader.java:46

Code:
    private int readDatatype(int count) {
        int ret = message[index++] & 0xFF;
        for (int i = 1; i <= count - 1; i++) {
            ret += ((message[index++] & 0xFF) << 8*i);
        }
        return ret;
    }
 
Elite Diviner
Joined
Mar 24, 2015
Messages
426
Reaction score
416
First off, that's a really confusing way to parse a number, why not just do:
Code:
int ret = 0;
for (int i = 0; i < count; i++) {
     ret += (message[index] & 0xFF) << (8 * i);
     index++;
}
return ret;

I see that you are using it for short, but are you using it for long too? That would cause an overflow because the return type is int.

But other than that I see nothing wrong in the code itself. Most likely index is already 2 when reading the short, so next it tries to read index 3/4 and then you get ArrayIndexOutOfBoundsException: 4. So for some reason, you don't actually have more than 3 bytes available, possibly because you are in the wrong branch of the handler (PlayerInteractionHandler does like 10+ things IIRC).
 
Upvote 0
Back
Top