|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
java.lang.ArrayIndexOutOfBoundsException |
« View previous topic :: View next topic » |
Author |
Message
|
jason_e |
Posted: Thu Oct 16, 2003 11:23 pm Post subject: java.lang.ArrayIndexOutOfBoundsException |
|
|
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 |
|
 |
bower5932 |
Posted: Fri Oct 17, 2003 4:46 am Post subject: |
|
|
 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 |
|
 |
jason_e |
Posted: Sat Oct 18, 2003 1:44 am Post subject: |
|
|
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 |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|