From 5a5861968674841a9b71b9a3cc500f384147fe73 Mon Sep 17 00:00:00 2001 From: Don Leckie Date: Thu, 6 Feb 2003 17:35:26 +0000 Subject: [PATCH] Fixed divide by zero bug that would cause a large class complexity number. git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1404 51baf565-9d33-0410-a72c-fc3788e3496d --- .../sourceforge/pmd/rules/CyclomaticComplexityRule.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexityRule.java b/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexityRule.java index 326a7293fe..adbf4b3fb9 100644 --- a/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexityRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/CyclomaticComplexityRule.java @@ -128,10 +128,10 @@ public class CyclomaticComplexityRule extends AbstractRule { m_entryStack.push(new Entry(node)); super.visit(node, data); - Entry classEntry = (Entry) m_entryStack.pop(); - double decisionPoints = (double) classEntry.m_decisionPoints; - double methodCount = (double) classEntry.m_methodCount; - int complexityAverage = (int) (Math.rint(decisionPoints / methodCount)); + Entry classEntry = (Entry) m_entryStack.pop(); + double decisionPoints = (double) classEntry.m_decisionPoints; + double methodCount = (double) classEntry.m_methodCount; + int complexityAverage = (methodCount == 0) ? 1 : (int) (Math.rint(decisionPoints / methodCount)); if ((complexityAverage >= getIntProperty("reportLevel")) || (classEntry.m_highestDecisionPoints >= getIntProperty("reportLevel")))