The Right Thing is to apply the same checks to overlaps() as to the
constructor.
static void checkValidRange(long position, long size) {
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (size < 0)
throw new IllegalArgumentException("Negative size");
if (position + size < 0)
throw new IllegalArgumentException("Negative position + size");
}
We could call the above in both the constructor and overlaps().
What happens if the caller passes negative values to overlaps()?
But this is slightly incompatible. No doubt some application is
relying on being able to pass negative args to overlaps(). Anyways, a
CCC is called for to settle this issue.
public final boolean overlaps(long position, long size) {
checkValidRange(position, size);
return ((position + size > this.position) &&
(this.position + this.size > position));
}
###@###.###
constructor.
static void checkValidRange(long position, long size) {
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (size < 0)
throw new IllegalArgumentException("Negative size");
if (position + size < 0)
throw new IllegalArgumentException("Negative position + size");
}
We could call the above in both the constructor and overlaps().
What happens if the caller passes negative values to overlaps()?
But this is slightly incompatible. No doubt some application is
relying on being able to pass negative args to overlaps(). Anyways, a
CCC is called for to settle this issue.
public final boolean overlaps(long position, long size) {
checkValidRange(position, size);
return ((position + size > this.position) &&
(this.position + this.size > position));
}
###@###.###
- csr for
-
JDK-8281623 (ch) FileLock: negative param and overflow issues
- Closed
- relates to
-
JDK-8288515 (ch) Unnecessary use of Math.addExact() in java.nio.channels.FileLock.overlaps()
- Resolved
-
JDK-8293469 lock(0, 0, true) throws OverlappingFileLockException
- Closed