xadisk
  1. xadisk
  2. XADISK-128

NativeXAFileInputStream skip method throws an unexpected IllegalArgumentException with message "New position cannot be negative or more than file size"

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.2.2
    • Component/s: filesystem
    • Labels:
      None

      Description

      Calling skip method on XAFileInputStream generate IllegalArgumentException due to wrongly calculated readPositionAfterSkip.
      This variable is evaluated with this expression:

      (NativeXAFileInputStream.java line 175)
      long readPositionAfterSkip = (position - byteBuffer.remaining()) + n;

      Using a position equals to 0 and skipping 200 bytes with a generic file larger than 200 bytes this expression return a negative value and than, the subsequential calling to "position(readPositionAfterSkip)" method, will throws IllegalArgumentException.

      Why don't simply use this?
      long readPositionAfterSkip = position + n;

      Thank you
      Marco

        Activity

        Hide
        Nitin Verma added a comment - - edited

        Thanks Marco.

        I could reproduce the issue if I try to skip some bytes just after opening the input stream, before any call to read etc. (so, a workaround is to read one byte anyway for the first time, xafis.read())

        The logic is failing because byteBuffer is not yet filled. There needs to be a check on flag filledAtleastOnce.

        We need to take into account the value of byteBuffer.remaining(); the "position" is not the position of the next byte in the file (to be returned to the user), it is an internal variable which is used to track from where in the file the buffer is to be filled next.

        Thanks Again...
        Nitin

        Show
        Nitin Verma added a comment - - edited Thanks Marco. I could reproduce the issue if I try to skip some bytes just after opening the input stream, before any call to read etc. (so, a workaround is to read one byte anyway for the first time, xafis.read()) The logic is failing because byteBuffer is not yet filled. There needs to be a check on flag filledAtleastOnce. We need to take into account the value of byteBuffer.remaining(); the "position" is not the position of the next byte in the file (to be returned to the user), it is an internal variable which is used to track from where in the file the buffer is to be filled next. Thanks Again... Nitin
        Hide
        Nitin Verma added a comment -

        Checked-in the changes to trunk.

        Show
        Nitin Verma added a comment - Checked-in the changes to trunk.

          People

          • Assignee:
            Nitin Verma
            Reporter:
            Marco Quaranta
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: