ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » java.lang.ArrayIndexOutOfBoundsException

Post new topic  Reply to topic
 java.lang.ArrayIndexOutOfBoundsException « View previous topic :: View next topic » 
Author Message
jason_e
PostPosted: Thu Oct 16, 2003 11:23 pm    Post subject: java.lang.ArrayIndexOutOfBoundsException Reply with quote

Apprentice

Joined: 19 Aug 2003
Posts: 33

Below is the code I'm using to read messages from a local queue. I received the above mentioned error intermittently. If I change mess.readMessage(lenght) to message.readUTF() everything works buy some of my data is lost. Any Suggestions?

Hashtable props = new Hashtable();
props.put(MQC.PORT_PROPERTY, new Integer(PORT));
qMgr = new MQQueueManager(QM, props);
int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;
myQueue = qMgr.accessQueue(LOCAL_Q, openOptions,null, null, null);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
MQMessage mess = new MQMessage();
mess.clearMessage();
mess.correlationId = MQC.MQCI_NONE;
mess.messageId = MQC.MQMI_NONE;
myQueue.get(mess, gmo);
String str = mess.readString(mess.getMessageLength());

java.lang.ArrayIndexOutOfBoundsException: -22

Regards,
Jason
Back to top
View user's profile Send private message
bower5932
PostPosted: Fri Oct 17, 2003 4:46 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

I think you may be getting bit by the difference between the number of bytes in the message and the number of characters getMessageLength() returns the number of bytes of message data. readString() reads a number of characters of data. From the Using Java manual under readString():
Quote:

length The number of characters to read (which may differ from the number of bytes according to the codeset, because some codesets use more than one byte per character).
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
jason_e
PostPosted: Sat Oct 18, 2003 1:44 am    Post subject: Reply with quote

Apprentice

Joined: 19 Aug 2003
Posts: 33

Your right, using readFully with a byte array fixed the issue.

byte b [] = new byte[mess.getMessageLength()];
mess.readFully(b);

I'm still woried about why mess.getMessageLenght() is working.

Do you agree with this logic:
readString failed because although getMessageLenght() returned the correct lenght of the message it was not long enough when trying to convert the message to a string because of encoding differences.

readFully now reads the message into a byte array and no conversion is happening between different encoding types because strings are out of the picture.

Agree? Disagree?

What would the implications be of using getDataLenght instead of getMessageLength()?

Cheers
Jason
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » java.lang.ArrayIndexOutOfBoundsException
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.