This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new c48ccaf Update some exceptions to UncheckedIOException. c48ccaf is described below commit c48ccaf1e60eb91b7849cba8d081f71bb9da630d Author: Gary Gregory <gardgreg...@gmail.com> AuthorDate: Thu Jan 28 15:00:53 2021 -0500 Update some exceptions to UncheckedIOException. Inspired by Boris Unckel's #195 GH PR. --- src/main/java/org/apache/commons/io/FileUtils.java | 15 ++++++++------- src/main/java/org/apache/commons/io/file/PathUtils.java | 11 ++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java index 7fe1a3d..987b7ad 100644 --- a/src/main/java/org/apache/commons/io/FileUtils.java +++ b/src/main/java/org/apache/commons/io/FileUtils.java @@ -27,6 +27,7 @@ import java.io.InputStream; 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 @@ public class FileUtils { } if (!causeList.isEmpty()) { - throw new IOExceptionList(directory.toString(), causeList); + throw new IOExceptionList(causeList); } } @@ -1922,7 +1923,7 @@ public class FileUtils { 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 class FileUtils { * * @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 class FileUtils { try { return lastModified(file); } catch (final IOException e) { - throw new IllegalArgumentException(file.toString(), e); + throw new UncheckedIOException(file.toString(), e); } } @@ -2130,7 +2131,7 @@ public class FileUtils { 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 @@ public class FileUtils { 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 @@ public class FileUtils { 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); } } diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java b/src/main/java/org/apache/commons/io/file/PathUtils.java index e5b4ad4..5d15251 100644 --- a/src/main/java/org/apache/commons/io/file/PathUtils.java +++ b/src/main/java/org/apache/commons/io/file/PathUtils.java @@ -20,6 +20,7 @@ package org.apache.commons.io.file; 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 final class PathUtils { /** * 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 final class PathUtils { 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); } /**