From a711bed911ba2039f2aae033114eae2597deecb8 Mon Sep 17 00:00:00 2001 From: Sebb Date: Fri, 26 Jul 2024 23:35:59 +0100 Subject: [PATCH 1/2] Replace assert with Exception --- .../org/apache/commons/io/input/ReadAheadInputStream.java | 8 ++++++-- .../org/apache/commons/io/input/ThrottledInputStream.java | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java b/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java index 3a9fe366ed0..86dae2d6569 100644 --- a/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java +++ b/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java @@ -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; @@ -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()); diff --git a/src/main/java/org/apache/commons/io/input/ThrottledInputStream.java b/src/main/java/org/apache/commons/io/input/ThrottledInputStream.java index c1826aa9df9..55f62697869 100644 --- a/src/main/java/org/apache/commons/io/input/ThrottledInputStream.java +++ b/src/main/java/org/apache/commons/io/input/ThrottledInputStream.java @@ -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; } @@ -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; } From 1360dccadd67e1ae8413390ed63dd7bb247e5b73 Mon Sep 17 00:00:00 2001 From: Sebb Date: Sat, 27 Jul 2024 00:23:30 +0100 Subject: [PATCH 2/2] Run basic test with experimental Java --- .github/workflows/maven.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1c698190dc2..87b00c76293 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -88,7 +88,12 @@ jobs: server-username: NEXUS_USER # env variable for username in deploy server-password: NEXUS_PW # env variable for token in deploy - name: Build with Maven + if: ${{ !matrix.experimental }} run: mvn --errors --show-version --batch-mode --no-transfer-progress -DtrimStackTrace=false + - name: Test only with Maven + if: ${{ matrix.experimental }} + # Skip PMD etc when using experimental Java + run: mvn --errors --show-version --batch-mode --no-transfer-progress -DtrimStackTrace=false clean test - name: Deploy SNAPSHOT using minimal build if: matrix.deploy && github.repository == 'apache/commons-io' && github.ref_name == 'master' env: