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

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7356 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Andreas Dangel
2011-09-26 19:41:32 +00:00
parent 165bb3a24c
commit 7275c9f0be
4 changed files with 26 additions and 3 deletions

View File

@ -343,6 +343,7 @@ Fix false positive on CastExpressions for UselessParentheses
Fix false positive where StringBuffer.setLength(0) was using default constructor size of 16, instead of actual constructor size.
Fix false negative for non-primitive types for VariableNamingConventions, also expanded scope to local and method/constructors, and enhanced customization options to choose between members/locals/parameters (all checked by default)
Improve TooManyMethods rule - thanks to a patch from Riku Nykanen
Improve DoNotCallSystemExit - thanks to a patch from Steven Christou
Correct -benchmark reporting of Rule visits via the RuleChain
Creating an Empty Code Ruleset and moved the following rules from Basic ruleset:
* Empty Code Rules

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

@ -250,20 +250,27 @@ Remote Interface of a Session EJB should not have a suffix.
externalInfoUrl="http://pmd.sourceforge.net/rules/java/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>
<example>
<![CDATA[
public void bar() {
System.exit(0); // never call this when running in an application server!
System.exit(0); // never call this when running in an application server!
}
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">