Skip to content

Commit

Permalink
8288515: (ch) Unnecessary use of Math.addExact() in java.nio.channels…
Browse files Browse the repository at this point in the history
….FileLock.overlaps()

Reviewed-by: alanb
  • Loading branch information
Brian Burkhalter committed Jun 23, 2022
1 parent 72f286a commit ef17ee4
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/java.base/share/classes/java/nio/channels/FileLock.java
Expand Up @@ -277,13 +277,10 @@ public final boolean overlaps(long position, long size) {
if (size < 0)
return false;

// 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
// Test whether this is below that. The sum cannot overflow as the
// size and position are immutable and were checked at construction.
if (this.position + this.size <= position) {
return false;
}

// if size == 0 then the specified lock range is unbounded and
Expand Down

1 comment on commit ef17ee4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.