Skip to content

Commit 606e72f

Browse files
elharogarydgregory
andauthored
[IO-814] Don't throw UncheckedIOException (#491)
* [IO-814] Don't throw UncheckedIOException * revert javadoc nits * revert javadoc nits * revert javadoc nits * revert javadoc nits * Remove unused imports * Javadoc --------- Co-authored-by: Gary Gregory <garydgregory@users.noreply.github.com>
1 parent 877b9e3 commit 606e72f

1 file changed

Lines changed: 13 additions & 19 deletions

File tree

src/main/java/org/apache/commons/io/file/PathUtils.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.io.OutputStream;
24-
import java.io.UncheckedIOException;
2524
import java.math.BigInteger;
2625
import java.net.URI;
2726
import java.net.URISyntaxException;
@@ -77,7 +76,6 @@
7776
import org.apache.commons.io.filefilter.IOFileFilter;
7877
import org.apache.commons.io.function.IOFunction;
7978
import org.apache.commons.io.function.IOSupplier;
80-
import org.apache.commons.io.function.Uncheck;
8179

8280
/**
8381
* NIO Path utilities.
@@ -1247,21 +1245,20 @@ private static boolean overrideReadOnly(final DeleteOption... deleteOptions) {
12471245
}
12481246

12491247
/**
1250-
* Reads the BasicFileAttributes from the given path. Returns null instead of throwing
1251-
* {@link UnsupportedOperationException}. Throws {@link Uncheck} instead of {@link IOException}.
1248+
* Reads the BasicFileAttributes from the given path. Returns null if the attributes can't be read.
12521249
*
12531250
* @param <A> The {@link BasicFileAttributes} type
12541251
* @param path The Path to test.
12551252
* @param type the {@link Class} of the file attributes required to read.
12561253
* @param options options indicating how to handle symbolic links.
1257-
* @return the file attributes.
1254+
* @return the file attributes or null if the attributes can't be read.
12581255
* @see Files#readAttributes(Path, Class, LinkOption...)
12591256
* @since 2.12.0
12601257
*/
12611258
public static <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) {
12621259
try {
1263-
return path == null ? null : Uncheck.apply(Files::readAttributes, path, type, options);
1264-
} catch (final UnsupportedOperationException e) {
1260+
return path == null ? null : Files.readAttributes(path, type, options);
1261+
} catch (final UnsupportedOperationException | IOException e) {
12651262
// For example, on Windows.
12661263
return null;
12671264
}
@@ -1274,16 +1271,14 @@ public static <A extends BasicFileAttributes> A readAttributes(final Path path,
12741271
* @return the path attributes.
12751272
* @throws IOException if an I/O error occurs.
12761273
* @since 2.9.0
1277-
* @deprecated Will be removed in 3.0.0 in favor of {@link #readBasicFileAttributes(Path, LinkOption...)}.
12781274
*/
1279-
@Deprecated
12801275
public static BasicFileAttributes readBasicFileAttributes(final Path path) throws IOException {
12811276
return Files.readAttributes(path, BasicFileAttributes.class);
12821277
}
12831278

12841279
/**
1285-
* Reads the BasicFileAttributes from the given path. Returns null instead of throwing
1286-
* {@link UnsupportedOperationException}.
1280+
* Reads the BasicFileAttributes from the given path. Returns null if the attributes
1281+
* can't be read.
12871282
*
12881283
* @param path the path to read.
12891284
* @param options options indicating how to handle symbolic links.
@@ -1295,12 +1290,11 @@ public static BasicFileAttributes readBasicFileAttributes(final Path path, final
12951290
}
12961291

12971292
/**
1298-
* Reads the BasicFileAttributes from the given path. Returns null instead of throwing
1299-
* {@link UnsupportedOperationException}.
1293+
* Reads the BasicFileAttributes from the given path. Returns null if the attributes
1294+
* can't be read.
13001295
*
13011296
* @param path the path to read.
13021297
* @return the path attributes.
1303-
* @throws UncheckedIOException if an I/O error occurs
13041298
* @since 2.9.0
13051299
* @deprecated Use {@link #readBasicFileAttributes(Path, LinkOption...)}.
13061300
*/
@@ -1310,8 +1304,8 @@ public static BasicFileAttributes readBasicFileAttributesUnchecked(final Path pa
13101304
}
13111305

13121306
/**
1313-
* Reads the DosFileAttributes from the given path. Returns null instead of throwing
1314-
* {@link UnsupportedOperationException}.
1307+
* Reads the DosFileAttributes from the given path. Returns null if the attributes
1308+
* can't be read.
13151309
*
13161310
* @param path the path to read.
13171311
* @param options options indicating how to handle symbolic links.
@@ -1327,8 +1321,8 @@ private static Path readIfSymbolicLink(final Path path) throws IOException {
13271321
}
13281322

13291323
/**
1330-
* Reads the PosixFileAttributes or DosFileAttributes from the given path. Returns null instead of throwing
1331-
* {@link UnsupportedOperationException}.
1324+
* Reads the PosixFileAttributes or DosFileAttributes from the given path. Returns null if the attributes
1325+
* can't be read.
13321326
*
13331327
* @param path The Path to read.
13341328
* @param options options indicating how to handle symbolic links.
@@ -1810,7 +1804,7 @@ public static Path writeString(final Path path, final CharSequence charSequence,
18101804
}
18111805

18121806
/**
1813-
* Does allow to instantiate.
1807+
* Prevents instantiation.
18141808
*/
18151809
private PathUtils() {
18161810
// do not instantiate.

0 commit comments

Comments
 (0)