Skip to content

Commit f343ad1

Browse files
authored
Add missing javadoc for exceptions thrown for invalid arguments (#339)
1 parent 3ae5d24 commit f343ad1

5 files changed

Lines changed: 21 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,8 @@ static String decodeUrl(final String url) {
11811181
*
11821182
* @param file The file to delete.
11831183
* @return the given file.
1184-
* @throws IOException if the file cannot be deleted.
1184+
* @throws NullPointerException if the parameter is {@code null}
1185+
* @throws IOException if the file cannot be deleted.
11851186
* @see File#delete()
11861187
* @since 2.9.0
11871188
*/
@@ -1196,6 +1197,7 @@ public static File delete(final File file) throws IOException {
11961197
*
11971198
* @param directory directory to delete
11981199
* @throws IOException in case deletion is unsuccessful
1200+
* @throws NullPointerException if the parameter is {@code null}
11991201
* @throws IllegalArgumentException if {@code directory} is not a directory
12001202
*/
12011203
public static void deleteDirectory(final File directory) throws IOException {
@@ -3119,8 +3121,8 @@ private static String[] toSuffixes(final String... extensions) {
31193121
* </p>
31203122
*
31213123
* @param file the File to touch.
3122-
* @throws IOException if an I/O problem occurs.
3123-
* @throws IOException if setting the last-modified time failed.
3124+
* @throws NullPointerException if the parameter is {@code null}.
3125+
* @throws IOException if setting the last-modified time failed or an I/O problem occurs.
31243126
*/
31253127
public static void touch(final File file) throws IOException {
31263128
Objects.requireNonNull(file, "file");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,8 @@ public static int read(final InputStream input, final byte[] buffer) throws IOEx
17701770
* @param offset initial offset into buffer
17711771
* @param length length to read, must be &gt;= 0
17721772
* @return actual length read; may be less than requested if EOF was reached
1773-
* @throws IOException if a read error occurs
1773+
* @throws IllegalArgumentException if length is negative
1774+
* @throws IOException if a read error occurs
17741775
* @since 2.2
17751776
*/
17761777
public static int read(final InputStream input, final byte[] buffer, final int offset, final int length)
@@ -1842,7 +1843,8 @@ public static int read(final Reader reader, final char[] buffer) throws IOExcept
18421843
* @param offset initial offset into buffer
18431844
* @param length length to read, must be &gt;= 0
18441845
* @return actual length read; may be less than requested if EOF was reached
1845-
* @throws IOException if a read error occurs
1846+
* @throws IllegalArgumentException if length is negative
1847+
* @throws IOException if a read error occurs
18461848
* @since 2.2
18471849
*/
18481850
public static int read(final Reader reader, final char[] buffer, final int offset, final int length)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ public static boolean fileContentEquals(final Path path1, final Path path2, fina
753753
* @param paths the array of files to apply the filter to.
754754
*
755755
* @return a subset of {@code files} that is accepted by the file filter.
756-
* @throws IllegalArgumentException if the filter is {@code null} or {@code files} contains a {@code null} value.
756+
* @throws NullPointerException if the filter is {@code null}
757+
* @throws IllegalArgumentException if {@code files} contains a {@code null} value.
757758
*
758759
* @since 2.9.0
759760
*/
@@ -1552,6 +1553,7 @@ static Set<FileVisitOption> toFileVisitOptionSet(final FileVisitOption... fileVi
15521553
* @return the given visitor.
15531554
*
15541555
* @throws IOException if an I/O error is thrown by a visitor method.
1556+
* @throws NullPointerException if the directory is {@code null}.
15551557
*/
15561558
public static <T extends FileVisitor<? super Path>> T visitFileTree(final T visitor, final Path directory) throws IOException {
15571559
requireExists(directory, "directory");
@@ -1692,6 +1694,7 @@ private static <R> R withPosixFileAttributes(final Path path, final LinkOption[]
16921694
* @param openOptions options How to open the file.
16931695
* @return The given path.
16941696
* @throws IOException if an I/O error occurs writing to or creating the file.
1697+
* @throws NullPointerException if either {@code path} or {@code charSequence} is {@code null}.
16951698
* @since 2.12.0
16961699
*/
16971700
public static Path writeString(final Path path, final CharSequence charSequence, final Charset charset, final OpenOption... openOptions)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2122
import static org.junit.jupiter.api.Assertions.assertTrue;
2223

2324
import java.io.File;
@@ -249,4 +250,9 @@ public void testDeletesRegular() throws Exception {
249250
assertEquals(0, top.list().length);
250251
}
251252

253+
@Test
254+
public void testDeleteDirectoryNullArgument() {
255+
assertThrows(NullPointerException.class, () -> FileUtils.deleteDirectory(null));
256+
}
257+
252258
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,6 +2687,8 @@ public void testToFileUtf8() throws Exception {
26872687

26882688
@Test
26892689
public void testTouch() throws IOException {
2690+
assertThrows(NullPointerException.class, () -> FileUtils.touch(null));
2691+
26902692
final File file = new File(tempDirFile, "touch.txt");
26912693
if (file.exists()) {
26922694
file.delete();

0 commit comments

Comments
 (0)