ShrinkWrap
  1. ShrinkWrap
  2. SHRINKWRAP-470

SeekableInMemoryByteChannel.truncate misimplements the contract

    Details

    • Type: Bug Bug
    • Status: Closed Closed (View Workflow)
    • Priority: Major Major
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 1.2.1
    • Component/s: None
    • Labels:
      None
    • Similar Issues:
      Show 5 results 

      Description

      At the tail end of truncate, is this logic:

      // If we've been given a size greater than we are
      if (newSize > currentSize) {
          // Reset the position only
          this.position = newSize;
      }
      

      which is not what the API says: "If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. If the given size is greater than or equal to the current size then the entity is not modified."

      I think you wanted this instead, which should be inside the above array truncation:

      // If we've been given a size less than we are
      if (newSize < currentSize) {
          // Reset the size only
          this.size = newSize;
      }
      

        Activity

        Hide
        Andrew Rubinger
        added a comment -

        Thanks for the report; was there an associated PR? Else we'll fix it up here.

        Show
        Andrew Rubinger
        added a comment - Thanks for the report; was there an associated PR? Else we'll fix it up here.
        Hide
        Under Flowerpot
        added a comment -

        No PR. I investigate shrinkwrap for its standalone features and implementation. I am experimenting with my own nio2 FileSystem implementation of Zookeeper.

        Show
        Under Flowerpot
        added a comment - No PR. I investigate shrinkwrap for its standalone features and implementation. I am experimenting with my own nio2 FileSystem implementation of Zookeeper.
        Hide
        Michal Matloka
        added a comment - - edited

        Hey,
        So API says:

        1. If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end.
        2. If the given size is greater than or equal to the current size then the entity is not modified.
        3. In either case, if the current position is greater than the given size then it is set to that size.

        1. is covered by https://github.com/shrinkwrap/shrinkwrap/blob/master/api-nio2/src/main/java/org/jboss/shrinkwrap/api/nio/file/SeekableInMemoryByteChannel.java#L250
        2. should be covered here https://github.com/shrinkwrap/shrinkwrap/blob/master/api-nio2/src/main/java/org/jboss/shrinkwrap/api/nio/file/SeekableInMemoryByteChannel.java#L259 but it should have form "do nothing", improved in PR to 'empty' block
        3. is covered https://github.com/shrinkwrap/shrinkwrap/blob/master/api-nio2/src/main/java/org/jboss/shrinkwrap/api/nio/file/SeekableInMemoryByteChannel.java#L245

        Andrew Rubinger please verify

        Show
        Michal Matloka
        added a comment - - edited Hey, So API says: 1. If the given size is less than the current size then the entity is truncated, discarding any bytes beyond the new end. 2. If the given size is greater than or equal to the current size then the entity is not modified. 3. In either case, if the current position is greater than the given size then it is set to that size. 1. is covered by https://github.com/shrinkwrap/shrinkwrap/blob/master/api-nio2/src/main/java/org/jboss/shrinkwrap/api/nio/file/SeekableInMemoryByteChannel.java#L250 2. should be covered here https://github.com/shrinkwrap/shrinkwrap/blob/master/api-nio2/src/main/java/org/jboss/shrinkwrap/api/nio/file/SeekableInMemoryByteChannel.java#L259 but it should have form "do nothing", improved in PR to 'empty' block 3. is covered https://github.com/shrinkwrap/shrinkwrap/blob/master/api-nio2/src/main/java/org/jboss/shrinkwrap/api/nio/file/SeekableInMemoryByteChannel.java#L245 Andrew Rubinger please verify
        Hide
        Andrew Rubinger
        added a comment -

        Upstream: 2bc9db2

        Show
        Andrew Rubinger
        added a comment - Upstream: 2bc9db2

          People

          • Assignee:
            Michal Matloka
            Reporter:
            Under Flowerpot
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: