From 3e8c42384b9b82e4fe45963ea6f9cbf7a93959e5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 1 Mar 2013 22:17:37 +0100 Subject: [PATCH] pmd: fixed #1064 Exception running PrematureDeclaration --- pmd/etc/changelog.txt | 1 + .../PrematureDeclarationRule.java | 5 ++--- .../xml/PrematureDeclaration.xml | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 1d27e95408..f98fd4ca22 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,5 +1,6 @@ ????? ??, 2013 - 5.0.3: +Fixed bug 1064: Exception running PrematureDeclaration Fixed bug 1068: CPD fails on broken symbolic links diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/PrematureDeclarationRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/PrematureDeclarationRule.java index b0729b75df..6351a9b548 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/PrematureDeclarationRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/optimizations/PrematureDeclarationRule.java @@ -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(); } /** diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/PrematureDeclaration.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/PrematureDeclaration.xml index edc64f437d..9b68cd9e0c 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/PrematureDeclaration.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/optimizations/xml/PrematureDeclaration.xml @@ -45,4 +45,24 @@ public class Bar { ]]> + + Bug #1064 Exception running PrematureDeclaration + 0 + +