From 7bdf0ac88c28ed589777d7e0ffb04d9cf0fa7805 Mon Sep 17 00:00:00 2001 From: mnhock Date: Tue, 11 Jun 2024 16:46:15 +0200 Subject: [PATCH] Rule methodsShouldNotThrowGenericException should check for Exception and RuntimeException --- docs/USERGUIDE.md | 2 +- src/main/java/com/enofex/taikai/java/JavaConfigurer.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/USERGUIDE.md b/docs/USERGUIDE.md index ab2d8b1..9962e94 100644 --- a/docs/USERGUIDE.md +++ b/docs/USERGUIDE.md @@ -62,7 +62,7 @@ Taikai.builder() .check(); ``` -- **Methods Should Not Throw Generic Exception**: Ensure that methods do not throw generic exceptions and use specific exception types instead. +- **Methods Should Not Throw Generic Exception**: Ensure that methods do not throw generic exceptions like `Exception` and `RuntimeException` and use specific exception types instead. ```java Taikai.builder() diff --git a/src/main/java/com/enofex/taikai/java/JavaConfigurer.java b/src/main/java/com/enofex/taikai/java/JavaConfigurer.java index 0a26c08..eaa8bad 100644 --- a/src/main/java/com/enofex/taikai/java/JavaConfigurer.java +++ b/src/main/java/com/enofex/taikai/java/JavaConfigurer.java @@ -46,7 +46,8 @@ public JavaConfigurer methodsShouldNotThrowGenericException() { public JavaConfigurer methodsShouldNotThrowGenericException(Configuration configuration) { return addRule(TaikaiRule.of(methods() .should().notDeclareThrowableOfType(Exception.class) - .as("Methods should not throw generic Exception"), configuration)); + .orShould().notDeclareThrowableOfType(RuntimeException.class) + .as("Methods should not throw generic Exception or RuntimeException"), configuration)); } public JavaConfigurer noUsageOfDeprecatedAPIs() {