#1304 UseCollectionIsEmpty false positive comparing to 1

This commit is contained in:
Andreas Dangel
2015-02-21 11:26:12 +01:00
parent cd8325dff3
commit bdf9c19a1d
3 changed files with 20 additions and 3 deletions
@@ -58,7 +58,7 @@ public class UseCollectionIsEmptyRule extends AbstractInefficientZeroCheck {
rules.put("==", Arrays.asList("0"));
rules.put("!=", Arrays.asList("0"));
rules.put(">=", Arrays.asList("0", "1"));
rules.put("<=", Arrays.asList("0", "1"));
rules.put("<=", Arrays.asList("0"));
return rules;
}
@@ -222,8 +222,8 @@ public class TestIsEmpty {
</test-code>
<test-code>
<description>#1230 UseCollectionIsEmpty gets false positives</description>
<expected-problems>6</expected-problems>
<expected-linenumbers>8,11,16,19,24,27</expected-linenumbers>
<expected-problems>4</expected-problems>
<expected-linenumbers>8,11,24,27</expected-linenumbers>
<code><![CDATA[
import java.util.ArrayList;
@@ -275,6 +275,22 @@ public class IsEmptyTest {
System.out.println("List is not empty, but not all non-empty lists will trigger this");
}
}
}
]]></code>
</test-code>
<test-code>
<description>#1304 UseCollectionIsEmpty false positive comparing to 1</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class PMDIsEmptyFalsePositive {
public void falsePositive() {
Collection<String> c = new ArrayList<String>();
if (c.size() <= 1) // false positive
{
// do something
}
}
}
]]></code>
</test-code>
+1
View File
@@ -38,6 +38,7 @@
* [#1298](https://sourceforge.net/p/pmd/bugs/1298/): Member variable int type with value 0xff000000 causes processing error
* [#1299](https://sourceforge.net/p/pmd/bugs/1299/): MethodReturnsInternalArray false positive
* [#1303](https://sourceforge.net/p/pmd/bugs/1303/): OverrideBothEqualsAndHashcodeRule does not work on class implements resolvable interfaces
* [#1304](https://sourceforge.net/p/pmd/bugs/1304/): UseCollectionIsEmpty false positive comparing to 1
* [#1305](https://sourceforge.net/p/pmd/bugs/1305/): variable declaration inside switch causes ClassCastException
* [#1306](https://sourceforge.net/p/pmd/bugs/1306/): False positive on duplicate when using static imports
* [#1308](https://sourceforge.net/p/pmd/bugs/1308/): PMD runs endlessly on some generated files