forked from phoedos/pmd
applied patch 2829888 : New rule: Calling Thread.run() - thanks to Andy Throgmorton
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.3.x@7323 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
parent
340e0f2583
commit
1668a79f03
@ -3,6 +3,9 @@
|
||||
Add options --ignore-literals and --ignore-identifiers to the CPD command line task, thanks to Cd-Man
|
||||
Fixed character reference in xml report - thanks to Seko
|
||||
|
||||
New Rule:
|
||||
basic: DontCallThreadRun - thanks to Andy Throgmorton
|
||||
|
||||
September 14, 2011 - 4.2.6:
|
||||
Fixed bug 2920057 - False + : CloseRessource whith an external getter
|
||||
Fixed bug 1808110 - Fixed performance issue on PreserveStackTrace
|
||||
|
@ -45,6 +45,7 @@ public class BasicRulesTest extends SimpleAggregatorTst {
|
||||
addRule("basic", "UnnecessaryConversionTemporary");
|
||||
addRule("basic", "UselessOperationOnImmutable");
|
||||
addRule("basic", "UselessOverridingMethod");
|
||||
addRule("basic", "DontCallThreadRun");
|
||||
}
|
||||
|
||||
public static junit.framework.Test suite() {
|
||||
|
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<test-data>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
basic use case - calls to run()
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
Thread t = new Thread();
|
||||
t.run(); // use t.start() instead
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description><![CDATA[
|
||||
basic use case - call to Thread().run()
|
||||
]]></description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
public void bar() {
|
||||
new Thread().run();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
@ -1211,7 +1211,7 @@ public class Test {
|
||||
</rule>
|
||||
|
||||
<rule name="EmptyInitializer"
|
||||
since="5.0"
|
||||
since="5.0"
|
||||
message="Empty initializer was found"
|
||||
class="net.sourceforge.pmd.rules.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#EmptyInitializer">
|
||||
@ -1240,6 +1240,41 @@ public class Foo {
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="DontCallThreadRun"
|
||||
since="4.3"
|
||||
message="Don't call Thread.run() explicitly, use Thread.start()"
|
||||
class="net.sourceforge.pmd.rules.XPathRule"
|
||||
externalInfoUrl="http://pmd.sourceforge.net/rules/basic.html#DontCallThreadRun">
|
||||
<description>
|
||||
Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
|
||||
</description>
|
||||
<priority>4</priority>
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//StatementExpression/PrimaryExpression
|
||||
[
|
||||
PrimaryPrefix
|
||||
[
|
||||
./Name[ends-with(@Image, '.run') or @Image = 'run']
|
||||
and substring-before(Name/@Image, '.') =//VariableDeclarator/VariableDeclaratorId/@Image
|
||||
[../../../Type/ReferenceType[ClassOrInterfaceType/@Image = 'Thread']]
|
||||
or (
|
||||
./AllocationExpression/ClassOrInterfaceType[@Image = 'Thread']
|
||||
and ../PrimarySuffix[@Image = 'run'])
|
||||
]
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
<example>
|
||||
<![CDATA[
|
||||
Thread t = new Thread();
|
||||
t.run(); // use t.start() instead
|
||||
new Thread().run(); // same violation
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
</ruleset>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user