Skip to content

Commit 660b89f

Browse files
author
Niall Pemberton
committed
IO-77 revert to throwing NullPointerException rather than IllegalArgumentException
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@610810 13f79535-47bb-0310-9956-ffa450edef68
1 parent acf5c4b commit 660b89f

2 files changed

Lines changed: 35 additions & 35 deletions

File tree

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,17 +1717,17 @@ public static Checksum checksum(File file, Checksum checksum) throws IOException
17171717
*
17181718
* @param srcDir the directory to be moved
17191719
* @param destDir the destination directory
1720-
* @throws IllegalArgumentException if source or destination is <code>null</code>
1720+
* @throws NullPointerException if source or destination is <code>null</code>
17211721
* @throws IOException if source or destination is invalid
17221722
* @throws IOException if an IO error occurs moving the file
17231723
* @since Commons IO 1.4
17241724
*/
17251725
public static void moveDirectory(File srcDir, File destDir) throws IOException {
17261726
if (srcDir == null) {
1727-
throw new IllegalArgumentException("Source must not be null");
1727+
throw new NullPointerException("Source must not be null");
17281728
}
17291729
if (destDir == null) {
1730-
throw new IllegalArgumentException("Destination must not be null");
1730+
throw new NullPointerException("Destination must not be null");
17311731
}
17321732
if (!srcDir.exists()) {
17331733
throw new FileNotFoundException("Source '" + srcDir + "' does not exist");
@@ -1756,17 +1756,17 @@ public static void moveDirectory(File srcDir, File destDir) throws IOException {
17561756
* @param destDir the destination file
17571757
* @param createDestDir If <code>true</code> create the destination directory,
17581758
* otherwise if <code>false</code> throw an IOException
1759-
* @throws IllegalArgumentException if source or destination is <code>null</code>
1759+
* @throws NullPointerException if source or destination is <code>null</code>
17601760
* @throws IOException if source or destination is invalid
17611761
* @throws IOException if an IO error occurs moving the file
17621762
* @since Commons IO 1.4
17631763
*/
17641764
public static void moveDirectoryToDirectory(File src, File destDir, boolean createDestDir) throws IOException {
17651765
if (src == null) {
1766-
throw new IllegalArgumentException( "Source must not be null" );
1766+
throw new NullPointerException("Source must not be null");
17671767
}
17681768
if (destDir == null) {
1769-
throw new IllegalArgumentException("Destination directory must not be null");
1769+
throw new NullPointerException("Destination directory must not be null");
17701770
}
17711771
if (!destDir.exists() && createDestDir) {
17721772
destDir.mkdirs();
@@ -1789,17 +1789,17 @@ public static void moveDirectoryToDirectory(File src, File destDir, boolean crea
17891789
*
17901790
* @param srcFile the file to be moved
17911791
* @param destFile the destination file
1792-
* @throws IllegalArgumentException if source or destination is <code>null</code>
1792+
* @throws NullPointerException if source or destination is <code>null</code>
17931793
* @throws IOException if source or destination is invalid
17941794
* @throws IOException if an IO error occurs moving the file
17951795
* @since Commons IO 1.4
17961796
*/
17971797
public static void moveFile(File srcFile, File destFile) throws IOException {
17981798
if (srcFile == null) {
1799-
throw new IllegalArgumentException( "Source must not be null" );
1799+
throw new NullPointerException("Source must not be null");
18001800
}
18011801
if (destFile == null) {
1802-
throw new IllegalArgumentException("Destination must not be null");
1802+
throw new NullPointerException("Destination must not be null");
18031803
}
18041804
if (!srcFile.exists()) {
18051805
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
@@ -1831,17 +1831,17 @@ public static void moveFile(File srcFile, File destFile) throws IOException {
18311831
* @param destDir the destination file
18321832
* @param createDestDir If <code>true</code> create the destination directory,
18331833
* otherwise if <code>false</code> throw an IOException
1834-
* @throws IllegalArgumentException if source or destination is <code>null</code>
1834+
* @throws NullPointerException if source or destination is <code>null</code>
18351835
* @throws IOException if source or destination is invalid
18361836
* @throws IOException if an IO error occurs moving the file
18371837
* @since Commons IO 1.4
18381838
*/
18391839
public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir) throws IOException {
18401840
if (srcFile == null) {
1841-
throw new IllegalArgumentException( "Source must not be null" );
1841+
throw new NullPointerException("Source must not be null");
18421842
}
18431843
if (destDir == null) {
1844-
throw new IllegalArgumentException("Destination directory must not be null");
1844+
throw new NullPointerException("Destination directory must not be null");
18451845
}
18461846
if (!destDir.exists() && createDestDir) {
18471847
destDir.mkdirs();
@@ -1865,17 +1865,17 @@ public static void moveFileToDirectory(File srcFile, File destDir, boolean creat
18651865
* @param destDir the destination directory
18661866
* @param createDestDir If <code>true</code> create the destination directory,
18671867
* otherwise if <code>false</code> throw an IOException
1868-
* @throws IllegalArgumentException if source or destination is <code>null</code>
1868+
* @throws NullPointerException if source or destination is <code>null</code>
18691869
* @throws IOException if source or destination is invalid
18701870
* @throws IOException if an IO error occurs moving the file
18711871
* @since Commons IO 1.4
18721872
*/
18731873
public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException {
18741874
if (src == null) {
1875-
throw new IllegalArgumentException( "Source must not be null" );
1875+
throw new NullPointerException("Source must not be null");
18761876
}
18771877
if (destDir == null) {
1878-
throw new IllegalArgumentException("Destination must not be null");
1878+
throw new NullPointerException("Destination must not be null");
18791879
}
18801880
if (!src.exists()) {
18811881
throw new FileNotFoundException("Source '" + src + "' does not exist");

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,14 +1351,14 @@ public boolean delete() {
13511351
public void testMoveFile_Errors() throws Exception {
13521352
try {
13531353
FileUtils.moveFile(null, new File("foo"));
1354-
fail("Expected IllegalArgumentException when source is null");
1355-
} catch (IllegalArgumentException e) {
1354+
fail("Expected NullPointerException when source is null");
1355+
} catch (NullPointerException e) {
13561356
// expected
13571357
}
13581358
try {
13591359
FileUtils.moveFile(new File("foo"), null);
1360-
fail("Expected IllegalArgumentException when destination is null");
1361-
} catch (IllegalArgumentException e) {
1360+
fail("Expected NullPointerException when destination is null");
1361+
} catch (NullPointerException e) {
13621362
// expected
13631363
}
13641364
try {
@@ -1400,14 +1400,14 @@ public void testMoveFileToDirectory() throws Exception {
14001400
public void testMoveFileToDirectory_Errors() throws Exception {
14011401
try {
14021402
FileUtils.moveFileToDirectory(null, new File("foo"), true);
1403-
fail("Expected IllegalArgumentException when source is null");
1404-
} catch (IllegalArgumentException e) {
1403+
fail("Expected NullPointerException when source is null");
1404+
} catch (NullPointerException e) {
14051405
// expected
14061406
}
14071407
try {
14081408
FileUtils.moveFileToDirectory(new File("foo"), null, true);
1409-
fail("Expected IllegalArgumentException when destination is null");
1410-
} catch (IllegalArgumentException e) {
1409+
fail("Expected NullPointerException when destination is null");
1410+
} catch (NullPointerException e) {
14111411
// expected
14121412
}
14131413
File testFile1 = new File(getTestDirectory(), "testMoveFileFile1");
@@ -1485,14 +1485,14 @@ public boolean renameTo( File dest ) {
14851485
public void testMoveDirectory_Errors() throws Exception {
14861486
try {
14871487
FileUtils.moveDirectory(null, new File("foo"));
1488-
fail("Expected IllegalArgumentException when source is null");
1489-
} catch (IllegalArgumentException e) {
1488+
fail("Expected NullPointerException when source is null");
1489+
} catch (NullPointerException e) {
14901490
// expected
14911491
}
14921492
try {
14931493
FileUtils.moveDirectory(new File("foo"), null);
1494-
fail("Expected IllegalArgumentException when destination is null");
1495-
} catch (IllegalArgumentException e) {
1494+
fail("Expected NullPointerException when destination is null");
1495+
} catch (NullPointerException e) {
14961496
// expected
14971497
}
14981498
try {
@@ -1549,14 +1549,14 @@ public void testMoveDirectoryToDirectory() throws Exception {
15491549
public void testMoveDirectoryToDirectory_Errors() throws Exception {
15501550
try {
15511551
FileUtils.moveDirectoryToDirectory(null, new File("foo"), true);
1552-
fail("Expected IllegalArgumentException when source is null");
1553-
} catch (IllegalArgumentException e) {
1552+
fail("Expected NullPointerException when source is null");
1553+
} catch (NullPointerException e) {
15541554
// expected
15551555
}
15561556
try {
15571557
FileUtils.moveDirectoryToDirectory(new File("foo"), null, true);
1558-
fail("Expected IllegalArgumentException when destination is null");
1559-
} catch (IllegalArgumentException e) {
1558+
fail("Expected NullPointerException when destination is null");
1559+
} catch (NullPointerException e) {
15601560
// expected
15611561
}
15621562
File testFile1 = new File(getTestDirectory(), "testMoveFileFile1");
@@ -1604,14 +1604,14 @@ public void testMoveToDirectory() throws Exception {
16041604
public void testMoveToDirectory_Errors() throws Exception {
16051605
try {
16061606
FileUtils.moveDirectoryToDirectory(null, new File("foo"), true);
1607-
fail("Expected IllegalArgumentException when source is null");
1608-
} catch (IllegalArgumentException e) {
1607+
fail("Expected NullPointerException when source is null");
1608+
} catch (NullPointerException e) {
16091609
// expected
16101610
}
16111611
try {
16121612
FileUtils.moveDirectoryToDirectory(new File("foo"), null, true);
1613-
fail("Expected IllegalArgumentException when destination is null");
1614-
} catch (IllegalArgumentException e) {
1613+
fail("Expected NullPointerException when destination is null");
1614+
} catch (NullPointerException e) {
16151615
// expected
16161616
}
16171617
File nonexistant = new File(getTestDirectory(), "nonexistant");

0 commit comments

Comments
 (0)