diff --git a/src/main/java/com/ibm/cldk/utils/AnalysisUtils.java b/src/main/java/com/ibm/cldk/utils/AnalysisUtils.java index a3d690c..89bc0f8 100644 --- a/src/main/java/com/ibm/cldk/utils/AnalysisUtils.java +++ b/src/main/java/com/ibm/cldk/utils/AnalysisUtils.java @@ -24,6 +24,7 @@ import com.ibm.wala.ipa.cha.IClassHierarchy; import com.ibm.wala.ssa.IR; import com.ibm.wala.ssa.SSAConditionalBranchInstruction; +import com.ibm.wala.ssa.SSASwitchInstruction; import com.ibm.wala.types.ClassLoaderReference; import java.util.*; @@ -86,16 +87,16 @@ public static Pair createAndPutNewCallableInSymbolTable(IMetho * @return int Cyclomatic complexity for method/constructor */ public static int getCyclomaticComplexity(IR ir) { - - try { - int branchCount = (int)Arrays.stream(ir.getInstructions()) - .filter(inst -> inst instanceof SSAConditionalBranchInstruction) - .count(); - return branchCount + 1; - } catch (NullPointerException nullPointerException) { - Log.error("Null pointer exception in getCyclomaticComplexity"); - throw new RuntimeException("Could not get cyclomatic complexity."); + if (ir == null) { + return 0; } + int conditionalBranchCount = (int) Arrays.stream(ir.getInstructions()) + .filter(inst -> inst instanceof SSAConditionalBranchInstruction) + .count(); + int switchBranchCount = Arrays.stream(ir.getInstructions()) + .filter(inst -> inst instanceof SSASwitchInstruction) + .map(inst -> ((SSASwitchInstruction) inst).getCasesAndLabels().length).reduce(0, Integer::sum); + return conditionalBranchCount + switchBranchCount + 1; } public static Pair getCallableFromSymbolTable(IMethod method) { diff --git a/src/main/java/com/ibm/cldk/utils/BuildProject.java b/src/main/java/com/ibm/cldk/utils/BuildProject.java index 94eab84..2846373 100644 --- a/src/main/java/com/ibm/cldk/utils/BuildProject.java +++ b/src/main/java/com/ibm/cldk/utils/BuildProject.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -158,7 +159,7 @@ private static boolean buildProject(String projectPath, String build) { * @return true if the streaming was successful, false otherwise. */ public static List buildProjectAndStreamClassFiles(String projectPath, String build) throws IOException { - return buildProject(projectPath, build) ? classFilesStream(projectPath) : null; + return buildProject(projectPath, build) ? classFilesStream(projectPath) : new ArrayList<>(); } /**