-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
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.
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.
- relates to
-
JDK-5041655 (ch) FileLock: negative param and overflow issues
-
- Resolved
-