From 110797a22ece175cb4f9b3857b3208aac4281fcd Mon Sep 17 00:00:00 2001 From: Sven Jacob Date: Thu, 16 Nov 2006 22:27:25 +0000 Subject: [PATCH] Fixed 1597987: NPE in new DaaRule git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4805 51baf565-9d33-0410-a72c-fc3788e3496d --- .../pmd/dfa/pathfinder/DAAPathFinder.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/dfa/pathfinder/DAAPathFinder.java b/pmd/src/net/sourceforge/pmd/dfa/pathfinder/DAAPathFinder.java index 2eda85eb18..97ac6c22c7 100644 --- a/pmd/src/net/sourceforge/pmd/dfa/pathfinder/DAAPathFinder.java +++ b/pmd/src/net/sourceforge/pmd/dfa/pathfinder/DAAPathFinder.java @@ -290,12 +290,14 @@ public class DAAPathFinder { private int countLoops() { DefaultMutableTreeNode treeNode = stack.getLastLeaf(); int counter = 0; - int childCount = treeNode.getParent().getChildCount(); - for (int i = 0; i < childCount; i++) { - DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i); - PathElement e = (PathElement) tNode.getUserObject(); - if (e != null && !e.isPseudoPathElement()) { - counter++; + if (treeNode.getParent() != null) { + int childCount = treeNode.getParent().getChildCount(); + for (int i = 0; i < childCount; i++) { + DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i); + PathElement e = (PathElement) tNode.getUserObject(); + if (e != null && !e.isPseudoPathElement()) { + counter++; + } } } return counter;