(ch) Unnecessary use of Math.addExact() in java.nio.channels.FileLock.overlaps()

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 20
    • Affects Version/s: 20
    • Component/s: core-libs
    • b04
    • generic
    • generic

      The check

              if (position + size < 0)
                  throw new IllegalArgumentException("Negative position + size");

      in the FileLock constructor guarantees that position() + size() does not overflow a long. Therefore the use of Math.addExact()

              // Test whether this is below that
              try {
                  if (Math.addExact(this.position, this.size) <= position)
                      return false;
              } catch (ArithmeticException ignored) {
                  // the sum of this.position and this.size overflows the range of
                  // long hence their mathematical sum is greater than position
              }

      in overlaps() is not necessary.

            Assignee:
            Brian Burkhalter
            Reporter:
            Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: