[java] Verify fix for BrokenNullCheck (#718)

Closes #718
This commit is contained in:
Andreas Dangel
2024-01-17 17:43:15 +01:00
parent b06d00fb40
commit 963a9a965c
2 changed files with 42 additions and 0 deletions

View File

@ -140,6 +140,7 @@ in the Migration Guide.
* java-design
* [#174](https://github.com/pmd/pmd/issues/174): \[java] SingularField false positive with switch in method that both assigns and reads field
* java-errorprone
* [#718](https://github.com/pmd/pmd/issues/718): \[java] BrokenNullCheck false positive with parameter/field confusion
* [#1831](https://github.com/pmd/pmd/issues/1831): \[java] DetachedTestCase reports abstract methods
* [#4719](https://github.com/pmd/pmd/pull/4719): \[java] UnnecessaryCaseChange: example doc toUpperCase() should compare to a capitalized string
* javascript
@ -763,6 +764,7 @@ Language specific fixes:
* [#4416](https://github.com/pmd/pmd/pull/4416): \[java] Fix reported line number in CommentContentRule
* java-errorprone
* [#659](https://github.com/pmd/pmd/issues/659): \[java] MissingBreakInSwitch - last default case does not contain a break
* [#718](https://github.com/pmd/pmd/issues/718): \[java] BrokenNullCheck false positive with parameter/field confusion
* [#1005](https://github.com/pmd/pmd/issues/1005): \[java] CloneMethodMustImplementCloneable triggers for interfaces
* [#1669](https://github.com/pmd/pmd/issues/1669): \[java] NullAssignment - FP with ternay and null as constructor argument
* [#1831](https://github.com/pmd/pmd/issues/1831): \[java] DetachedTestCase reports abstract methods

View File

@ -364,4 +364,44 @@ public class Library {
}
]]></code>
</test-code>
<test-code>
<description>[java] BrokenNullCheck false positive with parameter/field confusion #718 - Part 1</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class PmdTest {
public static boolean test1(final boolean hasFoo, final boolean hasBar, final Object foo, final Object bar) {
final boolean hasFooObject = foo != null;
final boolean hasBarObject = bar != null;
if (hasFoo == hasFooObject && hasBar == hasBarObject) {
return true;
} else {
return false;
}
}
public static boolean test2(final boolean hasFoo, final boolean hasBar, final Object foo, final Object bar) {
if (hasFoo == (foo != null) && hasBar == (bar != null)) {
return true;
} else {
return false;
}
}
}
]]></code>
</test-code>
<test-code>
<description>[java] BrokenNullCheck false positive with parameter/field confusion #718 - Part 2</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class PmdTest2 {
private Boolean f;
// parameter of the same name as field
public void f(Boolean f) {
if (f != null || this.f == null)
;
}
}
]]></code>
</test-code>
</test-data>