Skip to content

Commit 3dd65cb

Browse files
committed
fix: check for IOException, not AccessDeniedException
1 parent 733daef commit 3dd65cb

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2324
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2425
import static org.junit.jupiter.api.Assertions.assertNotNull;
2526
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -1820,7 +1821,11 @@ void testForceDeleteRestoresReadOnlyOnFailure(@TempDir Path tempDir) throws Exce
18201821
assertFalse(file.canWrite(), "Sanity: Windows canWrite() should be false when dos:readonly is set");
18211822

18221823
// 3) Attempt forced deletion; should fail with AccessDeniedException due to ACLs.
1823-
assertThrows(AccessDeniedException.class, () -> FileUtils.forceDelete(file), "Deletion must fail because DELETE/DELETE_CHILD are denied");
1824+
final IOException wrappedException = assertThrows(IOException.class,
1825+
() -> FileUtils.forceDelete(file),
1826+
"Deletion must fail because DELETE/DELETE_CHILD are denied");
1827+
final Throwable cause = wrappedException.getCause();
1828+
assertInstanceOf(AccessDeniedException.class, cause, "Cause must be AccessDeniedException");
18241829

18251830
// 4) Critical assertion: even though deletion failed, the DOS readonly flag must be restored.
18261831
assertTrue(isDosReadOnly(readOnly), "dos:readonly must be preserved/restored after failed deletion");

0 commit comments

Comments
 (0)