Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620184
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:31:34+00:00 2026-05-22T02:31:34+00:00

Hello all I hope someone can help me resolve this issue.. I’m curious as

  • 0

Hello all I hope someone can help me resolve this issue..

I’m curious as to why I’m getting this runtime error when from my perspective I shouldn’t
here’s the code section:

// Send Message to the Message Log 

public static void SendMesg() 
   {   
      String mesg_str = message_data.toString() ;        
      int msgstr_len = mesg_str.length();            // determine actual message length
      int array_len  = mesgwork.length ;     // determine actual mesgwork array length
      dt_stamp = getDateTime() ; 
      System.out.println(dt_stamp) ; 
      System.out.println( " LU62XnsCvr Diagnostic:");
      System.out.println(" LU62XCI0100: Method = SendMesg") ; 
      System.out.println(" Message to be sent: " ) ;
      System.out.println(mesg_str) ;
      System.out.println("mesg_str Length=") ;
      System.out.println(msgstr_len) ; 
      System.out.println("Derived mesgwork Length=") ;
      System.out.println(array_len) ; 
      System.out.println("Class Var MGBuffer length value: ") ;
      System.out.println(MGBUFLN) ; 
      System.out.println("Buffer Offset Value=") ;
      System.out.println(bufroffset) ;
      System.out.println( " LU62XnsCvr End Diagnostic") ;

      mesgwork = mesg_str.getBytes() ;        //Convert msg string to byte array 
      mesg_bufr.put( mesgwork, bufroffset, MGBUFLN ) ;// <= error occurs here  
      pgm_cntl = WRITE_MESG ;
      FileControl() ; 
      if (pgm_cntl == WRITE_ERROR) 
        { 
         sys_return = pgm_cntl ;
         SysEnd( sys_return ) ;
        }
      mesgcount = mesgcount + 1 ;                    // increment the message counter
      mesg_bufr.clear() ; 
      message_data.append("                ")  ;     // 16 bytes of blanks
      clearByteArray( mesgwork, MGBUFLN ) ;

   }  // End of Send Message log write sub-routine 

This is what’s displayed when I run the program:

2011.05.12 10:48:07    
LU62XnsCvr Diagnostic:  

 LU62XCI0100: Method = SendMesg
 Message to be sent:2011.05.12 10:48:07 LU62XCE0313: CPIC Return Code =1 CM Alloc  ConversationID=[B@201d201d  

mesg_str Length=89  

Derived mesgwork Length=192  

Class Var MGBuffer length value:192  

Buffer Offset Value=0  

 LU62XnsCvr End Diagnostic  


Exception in thread "main" java.lang.IndexOutOfBoundsException
        at java.nio.Buffer.checkBounds(Buffer.java:543)
        at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:177)
        at APPC_LU62.Runtime.LU62XnsCvr.SendMesg(LU62XnsCvr.java:652)
        at APPC_LU62.Runtime.LU62XnsCvr.StartConvrs(LU62XnsCvr.java:517)
        at APPC_LU62.Runtime.LU62XnsCvr.ProcessRqsts(LU62XnsCvr.java:398)
        at APPC_LU62.Runtime.LU62XnsCvr.main(LU62XnsCvr.java:357)

here’s integer variable MGBUFLN declared prior to any reference to it within LU62XnsCvr Class

final static int MGBUFLN   = 192 ;    //Message Buffer Length 

here’s the byte array that’s used as the “source” declared as a LU62XnsCvr Class member variable…

static byte[] mesgwork = new byte[MGBUFLN] ;

This I copied from the Oracle Java Doc website; don’t know exactly how current it is,
but it’s marked as java 6 and I’m running IBM’s SDK which is using java 1.6

public ByteBuffer put(byte[] src, int offset, int length)

Relative bulk put method (optional
operation). This method transfers
bytes into this buffer from the given
source array. If there are more
bytes to be copied from the array than
remain in this buffer, that is, if
length > remaining(), then no bytes
are transferred and a
BufferOverflowException is thrown.
Otherwise, this method copies length
bytes from the given array into this
buffer, starting at the given
offset in the array and at the current
position of this buffer. The
position of this buffer is then
incremented by length. In other
words, an invocation of this method of
the form dst.put(src, off, len) has
exactly the same effect as the loop

 for (int i = off; i < off + len; i++)
     dst.put(a[i]);

except that it first checks that there is
sufficient space in this buffer and it
is potentially much more efficient.

Parameters:

  • src – The array from
    which bytes are to be read
  • offset –
    The offset within the array of the
    first byte to be read; must be
    non-negative and no larger than
    array.length
  • length – The number of
    bytes to be read from the given array;
    must be non-negative and no larger
    than array.length – offset

Returns: This buffer

Throws:

  • BufferOverflowException – If there is
    insufficient space in this buffer
  • IndexOutOfBoundsException – If the
    preconditions on the offset and length
    parameters do not hold
  • ReadOnlyBufferException – If this
    buffer is read-only

I’m a little concerned with the statements:

Otherwise, this method copies length
bytes from the given array into this
buffer, starting at the given
offset in the array and at the current
position of this buffer. The
position of this buffer is then
incremented by length.

and then:

except that it first checks that there
is sufficient space in this buffer and
it is potentially much more
efficient.

// * my additional comments * //

Now I want to completely “fill” the 192 byte buffer (index therefore ranges from 0 – 191)
So IF as is put forth in the doc, the buffer is “incremented” by the length
(192 bytes in this case)

then it appears to me by implication the “logic” is going to add 192 bytes to index and
low and behold … we’re out of bounds on the index …

I’d really appreciate anyone’s opinion on this.
Waiting for your comments and/or suggestions…

Thanks

Guy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:31:35+00:00Added an answer on May 22, 2026 at 2:31 am

    In the line

    mesg_bufr.put( mesgwork, bufroffset, MGBUFLN ) ;
    

    you are trying to transfer MGBUFLN (ie 192) bytes from the mesgwork byte array to the buffer. But your mesgwork array has only 89 bytes in it, which is why you are getting the out of bounds exception.

    try this:

    mesg_bufr.put( mesgwork, bufroffset, mesgwork.length ) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello all I hope you can help me understand why getopt used an int
Hello can anybody solve this please I'm creating the object in the action class
First of all, hello all. This problem is driving me to insanity so I
(edited from original post to change BaseMessage to const BaseMessage&) Hello All, I'm very
This is my first post on the forum, hope all of you guys are
hello all i really need your help its my final project in university i
Hello wonderful stackoverflowers! I hope this question is within the scope of this site.
Usless Background Info Hello, all. This is my first post here, but I often
Hello all this is my code for the tab layout in to android i
Hello all you helpful folks @ stackoverflow! Best resources for Java GUI's? Looking at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.