From a846ccb01431eb5807ee9385e7803c429b655e41 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Thu, 12 Feb 2009 19:28:38 +0000 Subject: [PATCH] New rule in strictexceptions : AvoidCatchingGenericException patch submitted by Nadhamuni Kothapalle https://sourceforge.net/tracker/?func=detail&atid=479923&aid=2591604&group_id=56262 git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6842 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 2 + .../StrictExceptionRulesTest.java | 1 + .../xml/AvoidCatchingGenericException.xml | 48 +++++++++++++++++++ pmd/rulesets/strictexception.xml | 45 ++++++++++++++++- 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 pmd/regress/test/net/sourceforge/pmd/rules/strictexception/xml/AvoidCatchingGenericException.xml diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index eae501fa95..15e196257f 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,5 +1,7 @@ ???? - 4.2.6: +New rule: + StrictExceptions : AvoidCatchingGenericException February 08, 2009 - 4.2.5: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/StrictExceptionRulesTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/StrictExceptionRulesTest.java index bcca57f0bd..8e583a179e 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/StrictExceptionRulesTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/StrictExceptionRulesTest.java @@ -8,6 +8,7 @@ public class StrictExceptionRulesTest extends SimpleAggregatorTst { @Before public void setUp() { + addRule("strictexception", "AvoidCatchingGenericException"); addRule("strictexception", "AvoidCatchingNPE"); addRule("strictexception", "AvoidCatchingThrowable"); addRule("strictexception", "AvoidRethrowingException"); diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/xml/AvoidCatchingGenericException.xml b/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/xml/AvoidCatchingGenericException.xml new file mode 100644 index 0000000000..e6dcaf14ec --- /dev/null +++ b/pmd/regress/test/net/sourceforge/pmd/rules/strictexception/xml/AvoidCatchingGenericException.xml @@ -0,0 +1,48 @@ + + + + + 3 + + + + + 0 + + + + + 0 + + + \ No newline at end of file diff --git a/pmd/rulesets/strictexception.xml b/pmd/rulesets/strictexception.xml index bdd0a772c9..d41b7dd20c 100644 --- a/pmd/rulesets/strictexception.xml +++ b/pmd/rulesets/strictexception.xml @@ -330,5 +330,48 @@ public class Foo { + + + Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block + + 3 + + + + + + + + + + + + - +