Added Will Sargent's implementation of AvoidThreadGroup
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4284 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
pmd
etc
regress/test/net/sourceforge/pmd/rules
rulesets
xdocs
@ -1,5 +1,6 @@
|
||||
????, 2006 - 3.6:
|
||||
New rules:
|
||||
Basic ruleset: AvoidThreadGroup
|
||||
Design ruleset: UnsynchronizedStaticDateFormatter
|
||||
Strings ruleset: InefficientEmptyStringCheck, InsufficientStringBufferDeclaration
|
||||
Fixed bug 1414985 - ConsecutiveLiteralAppends now checks for intervening references between appends.
|
||||
|
@ -0,0 +1,46 @@
|
||||
package test.net.sourceforge.pmd.rules;
|
||||
|
||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
import net.sourceforge.pmd.PMD;
|
||||
|
||||
public class AvoidThreadGroupTest extends SimpleAggregatorTst {
|
||||
|
||||
private Rule rule;
|
||||
|
||||
public void setUp() throws RuleSetNotFoundException {
|
||||
rule = findRule("basic", "AvoidThreadGroup");
|
||||
}
|
||||
|
||||
public void testAll() {
|
||||
runTests(new TestDescriptor[]{
|
||||
new TestDescriptor(TEST1, "bad, using new ThreadGroup()", 1, rule),
|
||||
new TestDescriptor(TEST2, "bad, using Thread.getThreadGroup()", 1, rule),
|
||||
new TestDescriptor(TEST3, "bad, using System.getSecurityManager().getThreadGroup()", 1, rule),
|
||||
});
|
||||
}
|
||||
|
||||
private static final String TEST1 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar() {" + PMD.EOL +
|
||||
" ThreadGroup t = new ThreadGroup(\"my tg\");" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST2 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar() {" + PMD.EOL +
|
||||
" ThreadGroup t = Thread.currentThread().getThreadGroup();" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
private static final String TEST3 =
|
||||
"public class Foo {" + PMD.EOL +
|
||||
" void bar() {" + PMD.EOL +
|
||||
" ThreadGroup t = System.getSecurityManager().getThreadGroup();" + PMD.EOL +
|
||||
" }" + PMD.EOL +
|
||||
"}";
|
||||
|
||||
}
|
@ -999,5 +999,39 @@ if (method1().equals(a)) {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="AvoidThreadGroup"
|
||||
message="Avoid using ThreadGroup; it is not thread safe"
|
||||
class="net.sourceforge.pmd.rules.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#AvoidThreadGroup">
|
||||
<description>
|
||||
Avoid using ThreadGroup; although it is intended to be used in a threaded environment
|
||||
it contains methods that are not thread safe.
|
||||
</description>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//AllocationExpression/ClassOrInterfaceType[contains(@Image,'ThreadGroup')] |
|
||||
//PrimarySuffix[contains(@Image, 'getThreadGroup')]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Bar {
|
||||
void buz() {
|
||||
ThreadGroup tg = new ThreadGroup("My threadgroup") ;
|
||||
tg = new ThreadGroup(tg, "my thread group");
|
||||
tg = Thread.currentThread().getThreadGroup();
|
||||
tg = System.getSecurityManager().getThreadGroup();
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
|
||||
|
@ -48,6 +48,7 @@
|
||||
</subsection>
|
||||
<subsection name="Contributors">
|
||||
<ul>
|
||||
<li><a href="http://tersesystems.com/">Will Sargent</a> - Implemented AvoidThreadGroup, AvoidThrowingCertainExceptionTypesRule, AvoidCatchingNPERule, ExceptionAsFlowControlRule, URL updates for 'Similar projects' page</li>
|
||||
<li>Xavier Le Vourch - Patch to fix problem with TestClassWithoutTestCases, patch to fix rule name bugs in migration rulesets</li>
|
||||
<li>Benoit Xhenseval - noted Maven plugin bug (http://jira.codehaus.org/browse/MPPMD-24), bug report for UnusedPrivateMethod, suggestion to add elapsed time to XML report, bug report for ImmutableField, many bug reports (with good failure cases!), Ant task patch and bug report, XSLT patch, suggestion for improving XML report</li>
|
||||
<li>Barak Naveh - Reported and fixed bug in CallSuperInConstructor</li>
|
||||
@ -165,7 +166,6 @@
|
||||
<li>Matt Inger - CloneMethodMustImplementCloneable, CloneThrowsCloneNotSupportedException</li>
|
||||
<li>Morgan Schweers - Javascript highlighter for the PMD scoreboard</li>
|
||||
<li>Brandon Franklin - bug report for BeanMembersShouldSerializeRule, many PMD scoreboard ideas</li>
|
||||
<li><a href="http://tersesystems.com/">Will Sargent</a> - AvoidThrowingCertainExceptionTypesRule, AvoidCatchingNPERule, ExceptionAsFlowControlRule, URL updates for 'Similar projects' page</li>
|
||||
<li>Bertrand Mollinier Toublet - Bug report which led to platform character set encoding enhancement</li>
|
||||
<li>Choi Ki Soo - Found bug in XMLRenderer</li>
|
||||
<li><a href="http://www.fh-stralsund.de/mitarbeiter/powerslave,id,264,nodeid,75.html">Gero Wedemann</a> - Found bug in RuleSetFactory XPath message variable substitution</li>
|
||||
|
Reference in New Issue
Block a user