Update some exceptions to UncheckedIOException.
Inspired by Boris Unckel's GH PR.
MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
+import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLConnection;
@@ -352,7 +353,7 @@ private static void cleanDirectoryOnExit(final File directory) throws IOExceptio
}
if (!causeList.isEmpty()) {
- throw new IOExceptionList(directory.toString(), causeList);
+ throw new IOExceptionList(causeList);
}
}
@@ -1922,7 +1923,7 @@ public static boolean isSymlink(final File file) {
try {
return StreamIterator.iterator(streamFiles(directory, recursive, extensions));
} catch (final IOException e) {
- throw new IllegalStateException(e);
+ throw new UncheckedIOException(directory.toString(), e);
}
}
@@ -1986,7 +1987,7 @@ public static long lastModified(final File file) throws IOException {
*
* @param file The File to query.
* @return See {@link java.nio.file.attribute.FileTime#toMillis()}.
- * @throws IllegalArgumentException if an I/O error occurs.
+ * @throws UncheckedIOException if an I/O error occurs.
* @since 2.9.0
*/
public static long lastModifiedUnchecked(final File file) {
@@ -1996,7 +1997,7 @@ public static long lastModifiedUnchecked(final File file) {
try {
return lastModified(file);
} catch (final IOException e) {
- throw new IllegalArgumentException(file.toString(), e);
+ throw new UncheckedIOException(file.toString(), e);
}
}
@@ -2130,7 +2131,7 @@ private static AccumulatorPathVisitor listAccumulate(final File directory, final
final AccumulatorPathVisitor visitor = listAccumulate(directory, fileFilter, dirFilter);
return visitor.getFileList().stream().map(Path::toFile).collect(Collectors.toList());
} catch (final IOException e) {
- throw new IllegalArgumentException(e);
+ throw new UncheckedIOException(directory.toString(), e);
}
}
@@ -2148,7 +2149,7 @@ private static AccumulatorPathVisitor listAccumulate(final File directory, final
try {
return toList(streamFiles(directory, recursive, extensions));
} catch (final IOException e) {
- throw new IllegalArgumentException(e);
+ throw new UncheckedIOException(directory.toString(), e);
}
}
@@ -2179,7 +2180,7 @@ private static AccumulatorPathVisitor listAccumulate(final File directory, final
list.addAll(visitor.getDirList());
return list.stream().map(Path::toFile).collect(Collectors.toList());
} catch (final IOException e) {
- throw new IllegalStateException(e);
+ throw new UncheckedIOException(directory.toString(), e);
}
}

MODIFY
src/main/java/org/apache/commons/io/file/PathUtils.java
src/main/java/org/apache/commons/io/file/PathUtils.java
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.CopyOption;
@@ -862,18 +863,18 @@ public static BasicFileAttributes readBasicFileAttributes(final Path path) throw
/**
* Shorthand for {@code Files.readAttributes(path, BasicFileAttributes.class)} while wrapping {@link IOException}
- * as {@link IllegalStateException}.
+ * as {@link UncheckedIOException}.
*
* @param path the path to read.
* @return the path attributes.
- * @throws IllegalStateException if an I/O error occurs
+ * @throws UncheckedIOException if an I/O error occurs
* @since 2.9.0
*/
- public static BasicFileAttributes readBasicFileAttributesQuietly(final Path path) {
+ public static BasicFileAttributes readBasicFileAttributesUnchecked(final Path path) {
try {
return readBasicFileAttributes(path);
} catch (final IOException e) {
- throw new IllegalStateException(e);
+ throw new UncheckedIOException(e);
}
}
@@ -1046,7 +1047,7 @@ public static Path setReadOnly(final Path path, final boolean readOnly, final Li
public static Stream<Path> walk(final Path start, final PathFilter pathFilter, final int maxDepth,
final boolean readAttributes, final FileVisitOption... options) throws IOException {
return Files.walk(start, maxDepth, options).filter(path -> pathFilter.accept(path,
- readAttributes ? readBasicFileAttributesQuietly(path) : null) == FileVisitResult.CONTINUE);
+ readAttributes ? readBasicFileAttributesUnchecked(path) : null) == FileVisitResult.CONTINUE);
}
/**

Update some exceptions to UncheckedIOException.

Inspired by Boris Unckel's #195 GH PR.