Skip to content

Commit 368e3c1

Browse files
authored
refactor: Resolve open SonarCloud issues (#112)
Clear the open issues reported on the default branch: - java:S8714 (assertDoesNotThrow): replace try/catch + fail() blocks in OpenApiServerIT and ServerBaseTest with assertDoesNotThrow(...). - java:S8694 (Month enum): use java.time.Month constants in GsonJsonMapperTest instead of int month literals. - java:S109 (magic numbers): name the 4xx status bounds in BadRequestException (MIN/MAX_CLIENT_ERROR_STATUS). - java:S8433 (validation before super()): validate the status range before the super() call using a flexible constructor body. No behaviour change; test-only refactors plus an equivalent constructor reordering covered by BadRequestExceptionTest.
1 parent 87cd339 commit 368e3c1

4 files changed

Lines changed: 488 additions & 551 deletions

File tree

src/main/java/com/retailsvc/http/BadRequestException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
*/
1515
public final class BadRequestException extends RuntimeException {
1616

17-
private static final int DEFAULT_STATUS = 400;
17+
private static final int MIN_CLIENT_ERROR_STATUS = 400;
18+
private static final int MAX_CLIENT_ERROR_STATUS = 499;
19+
private static final int DEFAULT_STATUS = MIN_CLIENT_ERROR_STATUS;
1820

1921
private final int status;
2022
private final String pointer;
@@ -42,10 +44,10 @@ public BadRequestException(int status, String detail, String pointer, String key
4244

4345
public BadRequestException(
4446
int status, String detail, String pointer, String keyword, Throwable cause) {
45-
super(Objects.requireNonNull(detail, "detail must not be null"), cause);
46-
if (status < 400 || status > 499) {
47+
if (status < MIN_CLIENT_ERROR_STATUS || status > MAX_CLIENT_ERROR_STATUS) {
4748
throw new IllegalArgumentException("status must be 4xx, got " + status);
4849
}
50+
super(Objects.requireNonNull(detail, "detail must not be null"), cause);
4951
this.status = status;
5052
this.pointer = pointer;
5153
this.keyword = keyword;

0 commit comments

Comments
 (0)