Merge branch 'pr-1887'

This commit is contained in:
Andreas Dangel
2019-06-28 20:59:39 +02:00
3 changed files with 89 additions and 13 deletions

View File

@ -55,6 +55,8 @@ datetime field.
* [#1845](https://github.com/pmd/pmd/issues/1845): \[java] Regression in MethodReturnsInternalArray not handling enums
* java-design
* [#1094](https://github.com/pmd/pmd/issues/1094): \[java] UseUtilityClass should be LombokAware
* java-errorprone
* [#1853](https://github.com/pmd/pmd/issues/1853): \[java] False positive for NonStaticInitializer in anonymous class
* java-multithreading
* [#1814](https://github.com/pmd/pmd/issues/1814): \[java] UnsynchronizedStaticFormatter documentation and implementation wrong
* [#1815](https://github.com/pmd/pmd/issues/1815): \[java] False negative in UnsynchronizedStaticFormatter

View File

@ -2505,10 +2505,11 @@ confusing.
</description>
<priority>3</priority>
<properties>
<property name="version" value="2.0" />
<property name="xpath">
<value>
<![CDATA[
//Initializer[@Static='false']
//Initializer[@Static=false()][not(ancestor::*[3][self::AllocationExpression or self::EnumConstant])]
]]>
</value>
</property>

View File

@ -1,28 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<test-data
xmlns="http://pmd.sourceforge.net/rule-tests"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-data xmlns="http://pmd.sourceforge.net/rule-tests"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description><![CDATA[
bad
]]></description>
<description>bad</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
{}
}
]]></code>
]]></code>
</test-code>
<test-code>
<description><![CDATA[
static initializers are OK
]]></description>
<description>static initializers are OK</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
static {}
}
]]></code>
]]></code>
</test-code>
<test-code>
<description>Allowed in anonymous classes</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public Animation getStatusTransition() {
return new Transition() {
{
setCycleDuration(Duration.millis(1200));
}
@Override
protected void interpolate(double frac) {
// magic
}
};
}
}
]]></code>
</test-code>
<test-code>
<description>Flag in local class</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>3</expected-linenumbers>
<code><![CDATA[
public class Foo {
static {
class Local {{}}
}
}
]]></code>
</test-code>
<test-code>
<description>Allowed in enum constant</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>7</expected-linenumbers>
<code><![CDATA[
public enum Foo {
A {
{ setCycleDuration(Duration.millis(1200)); }
};
{ setCycleDuration(Duration.millis(1200)); }
}
]]></code>
</test-code>
<test-code>
<description>Flag in nested local class</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>7</expected-linenumbers>
<code><![CDATA[
public class Foo {
public Animation getStatusTransition() {
return new Transition() {
{
setCycleDuration(Duration.millis(1200));
class ImInAnon {{}} // should be flagged
}
@Override
protected void interpolate(double frac) {
// magic
}
};
}
}
]]></code>
</test-code>
</test-data>