[java] AddEmptyString - fix false positive with scoping
This commit is contained in:
@ -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]
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user