Skip to content

Commit 5cbb4c7

Browse files
author
Gary Gregory
committed
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.
1 parent f382ada commit 5cbb4c7

4 files changed

Lines changed: 33 additions & 14 deletions

File tree

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
with:
3838
java-version: ${{ matrix.java }}
3939
- name: Build with Maven
40-
run: mvn -V package --file pom.xml --no-transfer-progress
40+
run: mvn -V --file pom.xml --no-transfer-progress

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ file comparators, endian transformation classes, and much more.
304304
</properties>
305305

306306
<build>
307-
<defaultGoal>clean verify apache-rat:check clirr:check checkstyle:check javadoc:javadoc</defaultGoal>
307+
<!-- japicmp:cmp needs package to work from a jar -->
308+
<defaultGoal>clean package apache-rat:check japicmp:cmp checkstyle:check javadoc:javadoc</defaultGoal>
308309
<pluginManagement>
309310
<plugins>
310311
<plugin>

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,27 @@ public static void closeQuietly(final Closeable closeable, final Consumer<IOExce
367367
/**
368368
* Closes the given {@link Closeable} as a null-safe operation.
369369
*
370-
* @param closeables The resource(s) to close, may be null.
370+
* @param closeable The resource to close, may be null.
371371
* @throws IOException if an I/O error occurs.
372372
* @since 2.7
373373
*/
374+
public static void close(final Closeable closeable) throws IOException {
375+
if (closeable != null) {
376+
closeable.close();
377+
}
378+
}
379+
380+
/**
381+
* Closes the given {@link Closeable} as a null-safe operation.
382+
*
383+
* @param closeables The resource(s) to close, may be null.
384+
* @throws IOException if an I/O error occurs.
385+
* @since 2.8.0
386+
*/
374387
public static void close(final Closeable... closeables) throws IOException {
375388
if (closeables != null) {
376389
for (Closeable closeable : closeables) {
377-
if (closeable != null) {
378-
closeable.close();
379-
}
390+
close(closeable);
380391
}
381392
}
382393
}

src/test/java/org/apache/commons/io/IOUtilsTestCase.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,20 @@ public void setUp() {
146146
assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s"))));
147147
}
148148

149-
@Test public void testCloseMulti() {
149+
@Test
150+
public void testCloseMulti() {
150151
Closeable nulCloseable = null;
151-
Closeable [] closeables = {null, null};
152-
assertDoesNotThrow(() -> IOUtils.close(nulCloseable,nulCloseable));
152+
Closeable[] closeables = {null, null};
153+
assertDoesNotThrow(() -> IOUtils.close(nulCloseable, nulCloseable));
153154
assertDoesNotThrow(() -> IOUtils.close(closeables));
154-
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"),nulCloseable));
155-
assertThrows(IOException.class, () -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
155+
assertDoesNotThrow(() -> IOUtils.close((Closeable[]) null));
156+
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), nulCloseable));
157+
assertThrows(IOException.class,
158+
() -> IOUtils.close(nulCloseable, new YellOnCloseReader(new StringReader("s"))));
156159
}
157160

158-
@Test public void testCloseConsumer() {
161+
@Test
162+
public void testCloseConsumer() {
159163
Closeable nulCloseable = null;
160164
assertDoesNotThrow(() -> IOUtils.close(nulCloseable, null)); // null consumer
161165
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), null)); // null consumer
@@ -171,10 +175,13 @@ public void setUp() {
171175
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), silentConsumer));
172176
assertDoesNotThrow(() -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), silentConsumer));
173177

174-
final IOConsumer<IOException> noisyConsumer = i -> {throw i;}; // consumer passes on the throw
178+
final IOConsumer<IOException> noisyConsumer = i -> {
179+
throw i;
180+
}; // consumer passes on the throw
175181
assertDoesNotThrow(() -> IOUtils.close(nulCloseable, noisyConsumer)); // no throw
176182
assertDoesNotThrow(() -> IOUtils.close(new StringReader("s"), noisyConsumer)); // no throw
177-
assertThrows(IOException.class, () -> IOUtils.close(new YellOnCloseReader(new StringReader("s")),noisyConsumer)); // closeable throws
183+
assertThrows(IOException.class,
184+
() -> IOUtils.close(new YellOnCloseReader(new StringReader("s")), noisyConsumer)); // closeable throws
178185
}
179186

180187
@Test public void testCloseQuietly_AllCloseableIOException() {

0 commit comments

Comments
 (0)