Skip to content

Commit def9299

Browse files
committed
[IO-435] Document thrown IllegalArgumentException in FileUtils. Thanks to Dominik Stadler.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1611192 13f79535-47bb-0310-9956-ffa450edef68
1 parent 5696c52 commit def9299

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ file comparators, endian transformation classes, and much more.
204204
<contributor>
205205
<name>Ian Springer</name>
206206
</contributor>
207+
<contributor>
208+
<name>Dominik Stadler</name>
209+
</contributor>
207210
<contributor>
208211
<name>Masato Tezuka</name>
209212
</contributor>

src/changes/changes.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ The <action> type attribute can be add,update,fix,remove.
4747
<body>
4848
<!-- The release date is the date RC is cut -->
4949
<release version="2.5" date="2014-??-??" description="New features and bug fixes.">
50+
<action issue="IO-435" dev="tn" type="fix" due-to="Dominik Stadler">
51+
Document that FileUtils.deleteDirectory, directoryContains and cleanDirectory
52+
may throw an IllegalArgumentException in case the passed directory does not
53+
exist or is not a directory.
54+
</action>
5055
<action issue="IO-426" dev="ggregory" type="add">
5156
Add API IOUtils.closeQuietly(Closeable...)
5257
</action>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,7 @@ public static void copyToFile(final InputStream source, final File destination)
15571557
*
15581558
* @param directory directory to delete
15591559
* @throws IOException in case deletion is unsuccessful
1560+
* @throws IllegalArgumentException if {@code directory} does not exist or is not a directory
15601561
*/
15611562
public static void deleteDirectory(final File directory) throws IOException {
15621563
if (!directory.exists()) {
@@ -1628,6 +1629,8 @@ public static boolean deleteQuietly(final File file) {
16281629
* @return true is the candidate leaf is under by the specified composite. False otherwise.
16291630
* @throws IOException
16301631
* if an IO error occurs while checking the files.
1632+
* @throws IllegalArgumentException
1633+
* if {@code directory} is null or not a directory.
16311634
* @since 2.2
16321635
* @see FilenameUtils#directoryContains(String, String)
16331636
*/
@@ -1662,6 +1665,7 @@ public static boolean directoryContains(final File directory, final File child)
16621665
*
16631666
* @param directory directory to clean
16641667
* @throws IOException in case cleaning is unsuccessful
1668+
* @throws IllegalArgumentException if {@code directory} does not exist or is not a directory
16651669
*/
16661670
public static void cleanDirectory(final File directory) throws IOException {
16671671
if (!directory.exists()) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,15 @@ public void testChecksumDouble() throws Exception {
21852185
assertEquals(expectedValue, resultValue);
21862186
}
21872187

2188+
public void testDeleteDirectoryWithNonDirectory() throws Exception {
2189+
try {
2190+
FileUtils.deleteDirectory(testFile1);
2191+
fail();
2192+
} catch (final IllegalArgumentException ex) {
2193+
// expected
2194+
}
2195+
}
2196+
21882197
public void testDeleteQuietlyForNull() {
21892198
try {
21902199
FileUtils.deleteQuietly(null);

0 commit comments

Comments
 (0)