Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8323552

AbstractMemorySegmentImpl#mismatch returns -1 when comparing distinct areas of the same instance of MemorySegment

XMLWordPrintable

        I belive there is a bug in AbstractMemorySegmentImpl#mismatch method. It returns -1 (meaning that regions are equal) when passing the same instance of MemorySegment as both srcSegment and dstSegment parameters regardless of whether srcFromOffset and dstFromOffset as well as srcToOffset and dstToOffset are also equal.

        Here's the original code fragment:

        ```
            public static long mismatch(MemorySegment srcSegment, long srcFromOffset, long srcToOffset,
                                        MemorySegment dstSegment, long dstFromOffset, long dstToOffset) {
                AbstractMemorySegmentImpl srcImpl = (AbstractMemorySegmentImpl)Objects.requireNonNull(srcSegment);
                AbstractMemorySegmentImpl dstImpl = (AbstractMemorySegmentImpl)Objects.requireNonNull(dstSegment);
                long srcBytes = srcToOffset - srcFromOffset;
                long dstBytes = dstToOffset - dstFromOffset;
                srcImpl.checkAccess(srcFromOffset, srcBytes, true);
                dstImpl.checkAccess(dstFromOffset, dstBytes, true);
                if (dstImpl == srcImpl) {
                    srcImpl.checkValidState();
                    return -1;
                }
        ...
        ```

              pminborg Per-Ake Minborg
              plevart Peter Levart
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: