Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replace assert with Exception
  • Loading branch information
sebbASF committed Jul 26, 2024
commit a711bed911ba2039f2aae033114eae2597deecb8
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