Applied patch 3013807: DoNotCallSystemExit through Runtime. Thanks to Steven Christou.

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.3.x@7361 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Romain Pelisse 2011-09-29 14:28:37 +00:00
parent ee246222ae
commit 66ef2399e3
4 changed files with 30 additions and 5 deletions

View File

@ -5,9 +5,11 @@ Fixed character reference in xml report - thanks to Seko
Add C# support for CPD - thanks to Florian Bauer
Fix small bug in Rule Designer UI
Improve TooManyMethods rule - thanks to a patch from Riku Nykanen
Improve DoNotCallSystemExit - thanks to a patch from Steven Christou
New Rule:
basic: DontCallThreadRun - thanks to Andy Throgmorton
Basic ruleset: DontCallThreadRun - thanks to Andy Throgmorton
Logging with Jakarta Commons ruleset: GuardDebugLogging
September 14, 2011 - 4.2.6:
Fixed bug 2920057 - False + : CloseRessource whith an external getter
@ -40,7 +42,6 @@ New rule:
StrictExceptions : AvoidCatchingGenericException, AvoidLosingExceptionInformation
Naming : GenericsNaming
JSP: NoInlineScript
Logging with Jakarta Commons ruleset: GuardDebugLogging
February 08, 2009 - 4.2.5:

View File

@ -25,6 +25,20 @@ public class SystemCall {
// OK
application.exit(0);
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
basic violations with Runtime
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Bar {
public void foo() {
// NEVER DO THIS IN A APP SERVER !!!
Runtime.getRuntime().exit(0);
}
}
]]></code>
</test-code>

View File

@ -267,13 +267,18 @@ public class Foo {
class="net.sourceforge.pmd.rules.XPathRule"
externalInfoUrl="http://pmd.sourceforge.net/rules/j2ee.html#DoNotCallSystemExit">
<description>Web applications should not call System.exit(), since only the web container or the
application server should stop the JVM.
application server should stop the JVM. This rule also checks for the equivalent call Runtime.getRuntime().exit().
</description>
<priority>3</priority>
<properties>
<property name="xpath">
<value><![CDATA[
//Name[starts-with(@Image,'System.exit')]
//Name[
starts-with(@Image,'System.exit')
or
(starts-with(@Image,'Runtime.getRuntime') and ../../PrimarySuffix[ends-with(@Image,'exit')])
]
]]></value>
</property>
</properties>
@ -281,9 +286,13 @@ application server should stop the JVM.
<![CDATA[
public class Foo {
public void bar() {
// NEVER DO THIS IN A APP SERVER !!!
// never call this when running in an application server !
System.exit(0);
}
public void foo() {
Runtime.getRuntime().exit(0); // never stop the JVM manually, the container will do this.
}
}
]]></example>
</rule>

View File

@ -322,6 +322,7 @@
<li>Andreas Dangel - GodClass and LawOfDemeter rules, several bugfixes and cleanup</li>
<li>Riku Nykanen - patch improving TooManyMethods rule</li>
<li>Tammo van Lessen - new rule GuardDebugLogging for Jakarta Commons Logging ruleset.</li>
<li>Steven Christou - patch improving DoNotCallSystemExit rule</li>
</ul>
</subsection>
<subsection name="Organizations">