diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java index 185d68de3f..fe5e4e6fb7 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/RapidTypeAnalysisAlgorithm.java @@ -22,6 +22,7 @@ * #L% */ +import com.google.common.collect.ArrayListMultimap; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -49,7 +50,7 @@ public class RapidTypeAnalysisAlgorithm extends AbstractCallGraphAlgorithm { @Nonnull protected Set instantiatedClasses = Collections.emptySet(); - @Nonnull protected Map> ignoredCalls = Collections.emptyMap(); + @Nonnull protected ArrayListMultimap ignoredCalls = ArrayListMultimap.create(); /** * The constructor of the RTA algorithm. @@ -72,13 +73,13 @@ public CallGraph initialize() { public CallGraph initialize(@Nonnull List entryPoints) { // init helper data structures instantiatedClasses = new HashSet<>(); - ignoredCalls = new HashMap<>(); + ignoredCalls = ArrayListMultimap.create(); CallGraph cg = constructCompleteCallGraph(entryPoints); // delete the data structures instantiatedClasses = Collections.emptySet(); - ignoredCalls = Collections.emptyMap(); + ignoredCalls = ArrayListMultimap.create(); return cg; } @@ -198,13 +199,8 @@ private Stream resolveAllCallTargets( private void saveIgnoredCall( MethodSignature source, MethodSignature target, InvokableStmt invokableStmt) { ClassType notInstantiatedClass = target.getDeclClassType(); - List calls = ignoredCalls.get(notInstantiatedClass); Call ignoredCall = new Call(source, target, invokableStmt); - if (calls == null) { - calls = new ArrayList<>(); - ignoredCalls.put(notInstantiatedClass, calls); - } - calls.add(ignoredCall); + ignoredCalls.put(notInstantiatedClass, ignoredCall); } /** @@ -247,24 +243,22 @@ protected void preProcessingMethod( protected void includeIgnoredCallsToClass( ClassType classType, MutableCallGraph cg, Deque workList) { List newEdges = ignoredCalls.get(classType); - if (newEdges != null) { - newEdges.forEach( - call -> { - MethodSignature concreteTarget = - resolveConcreteDispatch(view, call.getTargetMethodSignature()).orElse(null); - if (concreteTarget == null) { - return; - } - addCallToCG( - call.getSourceMethodSignature(), - concreteTarget, - call.getInvokableStmt(), - cg, - workList); - }); - // can be removed because the instantiated class will be considered in future resolves - ignoredCalls.remove(classType); - } + newEdges.forEach( + call -> { + MethodSignature concreteTarget = + resolveConcreteDispatch(view, call.getTargetMethodSignature()).orElse(null); + if (concreteTarget == null) { + return; + } + addCallToCG( + call.getSourceMethodSignature(), + concreteTarget, + call.getInvokableStmt(), + cg, + workList); + }); + // can be removed because the instantiated class will be considered in future resolves + ignoredCalls.removeAll(classType); } /**