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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 20
    • 20
    • 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.

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

              Created:
              Updated:
              Resolved: