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

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 20
    • 20
    • core-libs
    • b04
    • generic
    • generic

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: