[java] AddEmptyString - fix false positive with scoping

This commit is contained in:
Andreas Dangel
2022-07-01 11:10:02 +02:00
parent cfcfa32dfb
commit f15cd8febc
2 changed files with 7 additions and 2 deletions

View File

@ -28,7 +28,7 @@ It is much better to use one of the type-specific `toString()` methods instead o
//AdditiveExpression/PrimaryExpression/PrimaryPrefix/Literal[@Image='""' and not(ancestor::Annotation)]
|
//AdditiveExpression/PrimaryExpression/PrimaryPrefix/Name
[@Image = //(LocalVariableDeclaration[@Final = true()]|FieldDeclaration[@Final = true()])
[@Image = (//FieldDeclaration[@Final = true()]|ancestor::MethodDeclaration//LocalVariableDeclaration[@Final = true()])
/VariableDeclarator[@Initializer = true()]
[VariableInitializer/Expression/PrimaryExpression/PrimaryPrefix/Literal[@Image='""']]
/VariableDeclaratorId/@Name]

View File

@ -102,7 +102,7 @@ class Main {
final String outerString1 = "";
final String outerString2 = "";
public static void main(String[] args) {
public static void main(String[] args, String otherString) {
final String innerString1 = "";
final String innerString2 = "";
@ -110,6 +110,11 @@ class Main {
String b = outerString2 + 514;
String c = innerString1 + 1919;
String d = innerString2 + 810;
String e = otherString + 42; // should not be flagged, otherString is a method parameter. Not to be confused with otherString local var in otherMethod
}
void otherMethod() {
final String otherString = "";
}
}
]]></code>