Skip to content

Commit

Permalink
Replace assert with Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Jul 26, 2024
1 parent 8e65e2b commit a711bed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ public long skip(final long n) throws IOException {
* @throws IOException if an I/O error occurs.
*/
private long skipInternal(final long n) throws IOException {
assert stateChangeLock.isLocked();
if (!stateChangeLock.isLocked()) {
throw new IllegalStateException("Expected stateChangeLock to be locked");
}
waitForAsyncReadComplete();
if (isEndOfStream()) {
return 0;
Expand All @@ -495,7 +497,9 @@ private long skipInternal(final long n) throws IOException {
int toSkip = (int) n;
// We need to skip from both active buffer and read ahead buffer
toSkip -= activeBuffer.remaining();
assert toSkip > 0; // skipping from activeBuffer already handled.
if (toSkip <= 0) { // skipping from activeBuffer already handled.
throw new IllegalStateException("Expected toSkip > 0, actual: " + toSkip);
}
activeBuffer.position(0);
activeBuffer.flip();
readAheadBuffer.position(toSkip + readAheadBuffer.position());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public static Builder builder() {
}

static long toSleepMillis(final long bytesRead, final long maxBytesPerSec, final long elapsedMillis) {
assert elapsedMillis >= 0 : "The elapsed time should be greater or equal to zero";
if (elapsedMillis < 0) {
throw new IllegalArgumentException("The elapsed time should be greater or equal to zero");
}
if (bytesRead <= 0 || maxBytesPerSec <= 0 || elapsedMillis == 0) {
return 0;
}
Expand All @@ -147,7 +149,9 @@ static long toSleepMillis(final long bytesRead, final long maxBytesPerSec, final

private ThrottledInputStream(final InputStream proxy, final long maxBytesPerSecond) {
super(proxy);
assert maxBytesPerSecond > 0 : "Bandwidth " + maxBytesPerSecond + " is invalid.";
if (maxBytesPerSecond <= 0) {
throw new IllegalArgumentException("Bandwidth " + maxBytesPerSecond + " is invalid.");
}
this.maxBytesPerSecond = maxBytesPerSecond;
}

Expand Down

0 comments on commit a711bed

Please sign in to comment.