Skip to content

Commit 53da859

Browse files
committed
fix: replace instanceof assertions with typed catch to satisfy SpotBugs JUA
SpotBugs JUA flags Assert.assertTrue(e instanceof T) because the message hides what type was actually thrown on failure. Using a typed catch block is stricter: any unexpected exception type propagates as a test error with the full stack trace, which is more informative than a failed boolean assertion.
1 parent beead6e commit 53da859

1 file changed

Lines changed: 8 additions & 14 deletions

File tree

api/src/test/java/io/minio/RetryTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,9 @@ public void testNoRetryOn404() throws Exception {
388388
try {
389389
client.listBuckets();
390390
Assert.fail("expected exception");
391-
} catch (Exception e) {
392-
Assert.assertTrue("expected ErrorResponseException", e instanceof ErrorResponseException);
393-
ErrorResponseException ere = (ErrorResponseException) e;
394-
Assert.assertEquals("NoSuchBucket", ere.errorResponse().code());
395-
Assert.assertEquals(404, ere.response().code());
391+
} catch (ErrorResponseException e) {
392+
Assert.assertEquals("NoSuchBucket", e.errorResponse().code());
393+
Assert.assertEquals(404, e.response().code());
396394
}
397395
// Must not retry — only 1 request should have been made
398396
Assert.assertEquals(1, server.getRequestCount());
@@ -419,11 +417,9 @@ public void testNoRetryOn403() throws Exception {
419417
try {
420418
client.listBuckets();
421419
Assert.fail("expected exception");
422-
} catch (Exception e) {
423-
Assert.assertTrue("expected ErrorResponseException", e instanceof ErrorResponseException);
424-
ErrorResponseException ere = (ErrorResponseException) e;
425-
Assert.assertEquals("AccessDenied", ere.errorResponse().code());
426-
Assert.assertEquals(403, ere.response().code());
420+
} catch (ErrorResponseException e) {
421+
Assert.assertEquals("AccessDenied", e.errorResponse().code());
422+
Assert.assertEquals(403, e.response().code());
427423
}
428424
Assert.assertEquals(1, server.getRequestCount());
429425
}
@@ -443,10 +439,8 @@ public void testRetryExhaustedThrowsLastError() throws Exception {
443439
try {
444440
client.listBuckets();
445441
Assert.fail("expected exception after exhausted retries");
446-
} catch (Exception e) {
447-
Assert.assertTrue(
448-
"expected InvalidResponseException", e instanceof InvalidResponseException);
449-
Assert.assertEquals(500, ((InvalidResponseException) e).responseCode());
442+
} catch (InvalidResponseException e) {
443+
Assert.assertEquals(500, e.responseCode());
450444
}
451445
Assert.assertEquals(3, server.getRequestCount());
452446
}

0 commit comments

Comments
 (0)