pmd: fixed #1064 Exception running PrematureDeclaration

This commit is contained in:
Andreas Dangel 2013-03-01 22:17:37 +01:00
parent a00532595a
commit 3e8c42384b
3 changed files with 23 additions and 3 deletions

View File

@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.3:
Fixed bug 1064: Exception running PrematureDeclaration
Fixed bug 1068: CPD fails on broken symbolic links

View File

@ -151,9 +151,8 @@ public class PrematureDeclarationRule extends AbstractJavaRule {
* @return String
*/
private static String varNameIn(ASTLocalVariableDeclaration node) {
ASTVariableDeclarator declarator = (ASTVariableDeclarator)node.jjtGetChild(1);
return ((ASTVariableDeclaratorId) declarator.jjtGetChild(0)).getImage();
ASTVariableDeclarator declarator = node.getFirstChildOfType(ASTVariableDeclarator.class);
return ((ASTVariableDeclaratorId) declarator.jjtGetChild(0)).getImage();
}
/**

View File

@ -45,4 +45,24 @@ public class Bar {
]]></code>
</test-code>
<test-code>
<description>Bug #1064 Exception running PrematureDeclaration</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Bar {
public int lengthSumOf(String[] strings) {
if (strings == null || strings.length == 0) return 0;
@SuppressWarnings("unchecked") Integer sum = 0; // optimal placement
for (int i=0; i<strings.length; i++) {
sum += strings[i].length();
}
return sum;
}
}
]]></code>
</test-code>
</test-data>