Restore binary compatibility in IOUtils with latest released version
2.7.
Refactor IOUtils to restore BC.
Make the GitHub build reuse the POM default goal.
Replace Apache CLIRR with JApiCmp since CLIRR is not Java 8 aware.
MODIFY
.github/workflows/maven.yml
.github/workflows/maven.yml
@@ -37,4 +37,4 @@ jobs:
with:
java-version: ${{ matrix.java }}
- name: Build with Maven
- run: mvn -V package --file pom.xml --no-transfer-progress
+ run: mvn -V --file pom.xml --no-transfer-progress

MODIFY
pom.xml
pom.xml
@@ -304,7 +304,8 @@ file comparators, endian transformation classes, and much more.
</properties>
<build>
- <defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check javadoc:javadoc</defaultGoal>
+ <!-- japicmp:cmp needs package to work from a jar -->
+ <defaultGoal>clean package apache-rat:check japicmp:cmp checkstyle:check javadoc:javadoc</defaultGoal>
<pluginManagement>
<plugins>
<plugin>

MODIFY
src/main/java/org/apache/commons/io/IOUtils.java
src/main/java/org/apache/commons/io/IOUtils.java
@@ -367,17 +367,28 @@ public static void closeQuietly(final Closeable closeable, final Consumer<IOExce
/**
* Closes the given {@link Closeable} as a null-safe operation.
*
- * @param closeables The resource(s) to close, may be null.
+ * @param closeable The resource to close, may be null.
* @throws IOException if an I/O error occurs.
* @since 2.7
*/
- public static void close(final Closeable... closeables) throws IOException {
- if (closeables != null) {
- for (Closeable closeable : closeables) {
+ public static void close(final Closeable closeable) throws IOException {
if (closeable != null) {
closeable.close();
}
}
+
+ /**
+ * Closes the given {@link Closeable} as a null-safe operation.
+ *
+ * @param closeables The resource(s) to close, may be null.
+ * @throws IOException if an I/O error occurs.
+ * @since 2.8.0
+ */
+ public static void close(final Closeable... closeables) throws IOException {
+ if (closeables != null) {
+ for (Closeable closeable : closeables) {
+ close(closeable);
+ }
}
}

MODIFY
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
src/test/java/org/apache/commons/io/IOUtilsTestCase.java
@@ -146,16 +146,20 @@ public void setUp() {
assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s"))));
}
- @Test public void testCloseMulti() {
+ @Test
+ public void testCloseMulti() {
Closeable nulCloseable = null;
Closeable[] closeables = {null, null};
assertDoesNotThrow(() -> IOUtils.close(nulCloseable, nulCloseable));
assertDoesNotThrow(() -> IOUtils.close(closeables));
+ assertDoesNotThrow(() -> IOUtils.close((Closeable[]) null));
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), nulCloseable));
- assertThrows(IOException.class, () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
+ assertThrows(IOException.class,
+ () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
}
- @Test public void testCloseConsumer() {
+ @Test
+ public void testCloseConsumer() {
Closeable nulCloseable = null;
assertDoesNotThrow(() -> IOUtils.close(nulCloseable, null)); // null consumer
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), null)); // null consumer
@@ -171,10 +175,13 @@ public void setUp() {
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), silentConsumer));
assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), silentConsumer));
- final IOConsumer<IOException> noisyConsumer = i -> {throw i;}; // consumer passes on the throw
+ final IOConsumer<IOException> noisyConsumer = i -> {
+ throw i;
+ }; // consumer passes on the throw
assertDoesNotThrow(() -> IOUtils.close(nulCloseable, noisyConsumer)); // no throw
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), noisyConsumer)); // no throw
- assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")),noisyConsumer)); // closeable throws
+ assertThrows(IOException.class,
+ () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), noisyConsumer)); // closeable throws
}
@Test public void testCloseQuietly_AllCloseableIOException() {

Restore binary compatibility in IOUtils with latest released version
2.7.

- Refactor IOUtils to restore BC.
- Make the GitHub build reuse the POM default goal.
- Replace Apache CLIRR with JApiCmp since CLIRR is not Java 8 aware.