Menu

#397 RetrieveUserSpace throws ArrayIndexOutOfBoundsException

jtopenlite
open
wanghuiq
5
2018-02-19
2017-11-21
No

Hi,

I tried to call the API QUSLMBR. Creating and deleting the userspace with the provided Program implementations in com.ibm.jtopenlite.command.program.object worked great. But retrieving the userspace data with RetrieveUserSpace didn't work.

I think the problem lies in setParameterOutputData() which ignores the maxLength parameter and always uses the passed lengthOfData from the constructor. This leads to an exception on the System.arraycopy method call when the lengthOfData is greater than the byte array buffer passed to this method (tempData).

Current implementation:

  public void setParameterOutputData(int parmIndex, byte[] tempData, int maxLength)
  {
    contents_ = new byte[lengthOfData_];
    System.arraycopy(tempData, 0, contents_, 0, lengthOfData_);
  }

Fix would be to use the minimum of those two value:

  public void setParameterOutputData(int parmIndex, byte[] tempData, int maxLength)
  {
    contents_ = new byte[lengthOfData_];
    System.arraycopy(tempData, 0, contents_, 0, Math.min(lengthOfData_, maxLength));
  }

Tested with JTOpen 9.4.

I attached part of my test for easier reproduction.

2 Attachments

Discussion

  • Mihael Schmidt

    Mihael Schmidt - 2017-11-21

    Forgot the jtopenlite Program class for the IBM i API QUSLMBR.

     
  • Mihael Schmidt

    Mihael Schmidt - 2017-11-23

    Oh. The fix should rather have been:

      public void setParameterOutputData(int parmIndex, byte[] tempData, int maxLength)
      {
        contents_ = new byte[Math.min(lengthOfData_, maxLength)];
        System.arraycopy(tempData, 0, contents_, 0, Math.min(lengthOfData_, maxLength));
      }
    
     
  • John Eberhard

    John Eberhard - 2018-02-19
    • assigned_to: wanghuiq
     

Log in to post a comment.