diff --git a/docs/pages/pmd/rules/java.md b/docs/pages/pmd/rules/java.md index 2e0c0f89b5..a7c4280504 100644 --- a/docs/pages/pmd/rules/java.md +++ b/docs/pages/pmd/rules/java.md @@ -136,6 +136,7 @@ folder: pmd/rules * [AvoidThrowingNewInstanceOfSameException](pmd_rules_java_design.html#avoidthrowingnewinstanceofsameexception): Catch blocks that merely rethrow a caught exception wrapped inside a new instance of the same typ... * [AvoidThrowingNullPointerException](pmd_rules_java_design.html#avoidthrowingnullpointerexception): Avoid throwing NullPointerExceptions manually. These are confusing because most people will assum... * [AvoidThrowingRawExceptionTypes](pmd_rules_java_design.html#avoidthrowingrawexceptiontypes): Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable,Excep... +* [AvoidUncheckedExceptionsInSignatures](pmd_rules_java_design.html#avoiduncheckedexceptionsinsignatures): A method or constructor should not explicitly declare unchecked exceptions in its'throws' clause.... * [ClassWithOnlyPrivateConstructorsShouldBeFinal](pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal): A class with only private constructors should be final, unless the private constructoris invoked ... * [CollapsibleIfStatements](pmd_rules_java_design.html#collapsibleifstatements): Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with... * [CouplingBetweenObjects](pmd_rules_java_design.html#couplingbetweenobjects): This rule counts the number of unique attributes, local variables, and return types within an obj... @@ -161,7 +162,6 @@ folder: pmd/rules * [NcssTypeCount](pmd_rules_java_design.html#ncsstypecount): Deprecated This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of l... * [NPathComplexity](pmd_rules_java_design.html#npathcomplexity): The NPath complexity of a method is the number of acyclic execution paths through that method.Whi... * [SignatureDeclareThrowsException](pmd_rules_java_design.html#signaturedeclarethrowsexception): A method/constructor shouldn't explicitly throw the generic java.lang.Exception, since itis uncle... -* [SignatureDeclareThrowsRuntimeException](pmd_rules_java_design.html#signaturedeclarethrowsruntimeexception): A method/constructor should not explicitly declare java.lang.RuntimeException or it's subclasses ... * [SimplifiedTernary](pmd_rules_java_design.html#simplifiedternary): Look for ternary operators with the form 'condition ? literalBoolean : foo'or 'condition ? foo : ... * [SimplifyBooleanAssertion](pmd_rules_java_design.html#simplifybooleanassertion): Avoid negation in an assertTrue or assertFalse test.For example, rephrase: assertTrue(!expr);a... * [SimplifyBooleanExpressions](pmd_rules_java_design.html#simplifybooleanexpressions): Avoid unnecessary comparisons in boolean expressions, they serve no purpose and impacts readability. diff --git a/docs/pages/pmd/rules/java/design.md b/docs/pages/pmd/rules/java/design.md index 41a604d0a1..23fb11d1fc 100644 --- a/docs/pages/pmd/rules/java/design.md +++ b/docs/pages/pmd/rules/java/design.md @@ -5,7 +5,7 @@ permalink: pmd_rules_java_design.html folder: pmd/rules/java sidebaractiveurl: /pmd_rules_java.html editmepath: ../pmd-java/src/main/resources/category/java/design.xml -keywords: Design, AbstractClassWithoutAnyMethod, AvoidCatchingGenericException, AvoidDeeplyNestedIfStmts, AvoidRethrowingException, AvoidThrowingNewInstanceOfSameException, AvoidThrowingNullPointerException, AvoidThrowingRawExceptionTypes, ClassWithOnlyPrivateConstructorsShouldBeFinal, CollapsibleIfStatements, CouplingBetweenObjects, CyclomaticComplexity, DataClass, DoNotExtendJavaLangError, ExceptionAsFlowControl, ExcessiveClassLength, ExcessiveImports, ExcessiveMethodLength, ExcessiveParameterList, ExcessivePublicCount, FinalFieldCouldBeStatic, GodClass, ImmutableField, LawOfDemeter, LogicInversion, LoosePackageCoupling, ModifiedCyclomaticComplexity, NcssConstructorCount, NcssCount, NcssMethodCount, NcssTypeCount, NPathComplexity, SignatureDeclareThrowsException, SignatureDeclareThrowsRuntimeException, SimplifiedTernary, SimplifyBooleanAssertion, SimplifyBooleanExpressions, SimplifyBooleanReturns, SimplifyConditional, SingularField, StdCyclomaticComplexity, SwitchDensity, TooManyFields, TooManyMethods, UselessOverridingMethod, UseObjectForClearerAPI, UseUtilityClass +keywords: Design, AbstractClassWithoutAnyMethod, AvoidCatchingGenericException, AvoidDeeplyNestedIfStmts, AvoidRethrowingException, AvoidThrowingNewInstanceOfSameException, AvoidThrowingNullPointerException, AvoidThrowingRawExceptionTypes, ClassWithOnlyPrivateConstructorsShouldBeFinal, CollapsibleIfStatements, CouplingBetweenObjects, CyclomaticComplexity, DataClass, DoNotExtendJavaLangError, ExceptionAsFlowControl, ExcessiveClassLength, ExcessiveImports, ExcessiveMethodLength, ExcessiveParameterList, ExcessivePublicCount, FinalFieldCouldBeStatic, GodClass, ImmutableField, LawOfDemeter, LogicInversion, LoosePackageCoupling, ModifiedCyclomaticComplexity, NcssConstructorCount, NcssCount, NcssMethodCount, NcssTypeCount, NPathComplexity, SignatureDeclareThrowsException, AvoidUncheckedExceptionsInSignatures, SimplifiedTernary, SimplifyBooleanAssertion, SimplifyBooleanExpressions, SimplifyBooleanReturns, SimplifyConditional, SingularField, StdCyclomaticComplexity, SwitchDensity, TooManyFields, TooManyMethods, UselessOverridingMethod, UseObjectForClearerAPI, UseUtilityClass language: Java --- @@ -285,6 +285,36 @@ public class Foo { ``` +## AvoidUncheckedExceptionsInSignatures + +**Since:** PMD 6.13.0 + +**Priority:** Medium (3) + +A method or constructor should not explicitly declare unchecked exceptions in its +`throws` clause. Java doesn't force the caller to handle an unchecked exception, +so it's unnecessary except for documentation. A better practice is to document the +exceptional cases with a `@throws` Javadoc tag, which allows being more descriptive. + +**This rule is defined by the following XPath expression:** +``` xpath +//MethodDeclaration/NameList/Name[pmd-java:typeIs("java.lang.RuntimeException")] +| +//ConstructorDeclaration/NameList/Name[pmd-java:typeIs("java.lang.RuntimeException")] +``` + +**Example(s):** + +``` java +public void foo() throws RuntimeException { +} +``` + +**Use this rule by referencing it:** +``` xml + +``` + ## ClassWithOnlyPrivateConstructorsShouldBeFinal **Since:** PMD 4.1 @@ -1343,30 +1373,6 @@ public void foo() throws Exception { ``` -## SignatureDeclareThrowsRuntimeException - -**Since:** PMD 1.2 - -**Priority:** Medium (3) - -A method/constructor should not explicitly declare java.lang.RuntimeException or it's subclasses in throws clause of it's signature, since it is advised to avoid declaring unchecked exceptions in method signature. - -**This rule is defined by the following Java class:** [net.sourceforge.pmd.lang.java.rule.design.SignatureDeclareThrowsRuntimeExceptionRule](https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SignatureDeclareThrowsRuntimeExceptionRule.java) - -**Example(s):** - -``` java -import java.lang.RuntimeException; - -public void foo() throws RuntimeException { -} -``` - -**Use this rule by referencing it:** -``` xml - -``` - ## SimplifiedTernary **Since:** PMD 5.4.0