[java] UseEqualsToCompareStrings: Fix false positives
This commit is contained in:
2 files changed
+15
-2
No files matched your search
@@ -3404,7 +3404,9 @@ public class Main {
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_errorprone.html#useequalstocomparestrings">
|
||||
<description>
|
||||
Using '==' or '!=' to compare strings only works if intern version is used on both sides.
|
||||
Using '==' or '!=' to compare strings only works if the internalized string (`String#intern()`)
|
||||
is used on both sides.
|
||||
|
||||
Use the `equals()` method instead.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
@@ -3412,7 +3414,8 @@ Use the `equals()` method instead.
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//InfixExpression[count(*[pmd-java:typeIsExactly('java.lang.String')]) = 2]
|
||||
//InfixExpression[@Operator='==' or @Operator='!=']
|
||||
[count(*[pmd-java:typeIsExactly('java.lang.String')]) = 2]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
|
||||
+10
@@ -184,4 +184,14 @@ public class O {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>False positive with string concatentation</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {{
|
||||
String a = "b" + "c";
|
||||
}}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
Reference in new issue
Block a user