Fixes #1484 UnusedLocalVariable - false positive - parenthesis
This commit is contained in:
@ -1,4 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
|
* Fix for an expression within an additive expression that was
|
||||||
|
* wrongly taken as a cast expression.
|
||||||
|
* Bug #1484
|
||||||
|
*
|
||||||
|
* Andreas Dangel 05/2016
|
||||||
|
*====================================================================
|
||||||
* Fix for Lambda expression with one variable
|
* Fix for Lambda expression with one variable
|
||||||
* Bug #1470
|
* Bug #1470
|
||||||
*
|
*
|
||||||
@ -1755,6 +1761,7 @@ void UnaryExpressionNotPlusMinus() #UnaryExpressionNotPlusMinus((jjtn000.getImag
|
|||||||
{}
|
{}
|
||||||
{
|
{
|
||||||
( "~" {jjtThis.setImage("~");} | "!" {jjtThis.setImage("!");} ) UnaryExpression()
|
( "~" {jjtThis.setImage("~");} | "!" {jjtThis.setImage("!");} ) UnaryExpression()
|
||||||
|
| LOOKAHEAD("(" <IDENTIFIER> ")" "+") PostfixExpression()
|
||||||
| LOOKAHEAD( CastExpression() ) CastExpression()
|
| LOOKAHEAD( CastExpression() ) CastExpression()
|
||||||
| LOOKAHEAD("(" Type() ")" "(") CastExpression()
|
| LOOKAHEAD("(" Type() ")" "(") CastExpression()
|
||||||
| PostfixExpression()
|
| PostfixExpression()
|
||||||
|
@ -131,6 +131,21 @@ public class ParserCornersTest extends ParserTst {
|
|||||||
parseJava18(c);
|
parseJava18(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This triggered bug #1484 UnusedLocalVariable - false positive - parenthesis
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void stringConcatentationShouldNotBeCast() throws Exception {
|
||||||
|
String code = "public class Test {\n" +
|
||||||
|
" public static void main(String[] args) {\n" +
|
||||||
|
" System.out.println(\"X\" + (args) + \"Y\");\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
ASTCompilationUnit cu = parseJava18(code);
|
||||||
|
Assert.assertEquals(0, cu.findDescendantsOfType(ASTCastExpression.class).size());
|
||||||
|
}
|
||||||
|
|
||||||
private String readAsString(String resource) {
|
private String readAsString(String resource) {
|
||||||
InputStream in = ParserCornersTest.class.getResourceAsStream(resource);
|
InputStream in = ParserCornersTest.class.getResourceAsStream(resource);
|
||||||
try {
|
try {
|
||||||
|
@ -342,6 +342,32 @@ public class Foo {
|
|||||||
// do something
|
// do something
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
|
|
||||||
|
<test-code>
|
||||||
|
<description>#1484 UnusedLocalVariable - false positive - parenthesis</description>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
list.add("first");
|
||||||
|
list.add("second");
|
||||||
|
|
||||||
|
int notEmpty = 0;
|
||||||
|
for (String string : list) {
|
||||||
|
if (!string.isEmpty()) {
|
||||||
|
notEmpty++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(list.size() + " (" + (notEmpty) + " not empty)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
**Bugfixes:**
|
**Bugfixes:**
|
||||||
|
|
||||||
|
* java-unusedcode/UnusedLocalVariable
|
||||||
|
* [#1484](https://sourceforge.net/p/pmd/bugs/1484/): UnusedLocalVariable - false positive - parenthesis
|
||||||
|
|
||||||
**API Changes:**
|
**API Changes:**
|
||||||
|
|
||||||
* New command line parameter for PMD: `-norulesetcompatibility` - this disables the ruleset factory
|
* New command line parameter for PMD: `-norulesetcompatibility` - this disables the ruleset factory
|
||||||
|
Reference in New Issue
Block a user