8288515: (ch) Unnecessary use of Math.addExact() in java.nio.channels.FileLock.overlaps()
Reviewed-by: alanb
This commit is contained in:
parent
72f286a9ba
commit
ef17ee4dea
@ -277,13 +277,10 @@ public abstract class FileLock implements AutoCloseable {
|
|||||||
if (size < 0)
|
if (size < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Test whether this is below that
|
// Test whether this is below that. The sum cannot overflow as the
|
||||||
try {
|
// size and position are immutable and were checked at construction.
|
||||||
if (Math.addExact(this.position, this.size) <= position)
|
if (this.position + this.size <= position) {
|
||||||
return false;
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if size == 0 then the specified lock range is unbounded and
|
// if size == 0 then the specified lock range is unbounded and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user