From 023e56614cea99c36d52a85833f20d542b813421 Mon Sep 17 00:00:00 2001 From: "M.Schmidt" Date: Thu, 21 Dec 2023 14:16:22 +0100 Subject: [PATCH 1/3] fix IAE:Node not found from vertexOf(..) via .callsTo(..) --- .../java/sootup/callgraph/AbstractCallGraphAlgorithm.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java index 7ab1607c983..36e798e3e01 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java @@ -319,7 +319,9 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp Set newMethodSignatures = clazz.getMethods().stream().map(Method::getSignature).collect(Collectors.toSet()); + if (newMethodSignatures.stream().anyMatch(oldCallGraph::containsMethod)) { + // FIXME: [ms] handle better - remove from entry point signatures in this case throw new IllegalArgumentException("CallGraph already contains methods from " + classType); } @@ -354,8 +356,10 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp MethodSignature overridingMethodSig = clazz.getMethod(overriddenMethodSig.getSubSignature()).get().getSignature(); - for (MethodSignature callingMethodSig : updated.callsTo(overriddenMethodSig)) { - updated.addCall(callingMethodSig, overridingMethodSig); + if( updated.containsMethod(overriddenMethodSig) ){ + for (MethodSignature callingMethodSig : updated.callsTo(overriddenMethodSig)) { + updated.addCall(callingMethodSig, overridingMethodSig); + } } }); From 011a239693610050316c8120e306a6f859de84d5 Mon Sep 17 00:00:00 2001 From: "M.Schmidt" Date: Thu, 21 Dec 2023 14:16:50 +0100 Subject: [PATCH 2/3] make API return type more convenient --- .../java/sootup/callgraph/AbstractCallGraphAlgorithm.java | 3 +-- .../src/main/java/sootup/java/core/JavaSootClass.java | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java index 36e798e3e01..842335ddd6b 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java @@ -319,7 +319,6 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp Set newMethodSignatures = clazz.getMethods().stream().map(Method::getSignature).collect(Collectors.toSet()); - if (newMethodSignatures.stream().anyMatch(oldCallGraph::containsMethod)) { // FIXME: [ms] handle better - remove from entry point signatures in this case throw new IllegalArgumentException("CallGraph already contains methods from " + classType); @@ -356,7 +355,7 @@ public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassTyp MethodSignature overridingMethodSig = clazz.getMethod(overriddenMethodSig.getSubSignature()).get().getSignature(); - if( updated.containsMethod(overriddenMethodSig) ){ + if (updated.containsMethod(overriddenMethodSig)) { for (MethodSignature callingMethodSig : updated.callsTo(overriddenMethodSig)) { updated.addCall(callingMethodSig, overridingMethodSig); } diff --git a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java index c4ed4b40049..a4962269df4 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java +++ b/sootup.java.core/src/main/java/sootup/java/core/JavaSootClass.java @@ -37,6 +37,7 @@ import sootup.core.signatures.MethodSubSignature; import sootup.core.types.ClassType; import sootup.core.types.Type; +import sootup.java.core.types.JavaClassType; import sootup.java.core.views.JavaView; public class JavaSootClass extends SootClass { @@ -45,6 +46,12 @@ public JavaSootClass(JavaSootClassSource classSource, SourceType sourceType) { super(classSource, sourceType); } + @Nonnull + @Override + public JavaClassType getType() { + return (JavaClassType) super.getType(); + } + /** * Get all annotations on this class. If provided with a View, will also resolve all inherited * annotations from super classes. From 54191f111328f96e2eedc5421e3ac06db0be0005 Mon Sep 17 00:00:00 2001 From: "M.Schmidt" Date: Thu, 21 Dec 2023 15:04:24 +0100 Subject: [PATCH 3/3] not throwing an error if not necessary when nothing was added to the CallGraph --- .../callgraph/AbstractCallGraphAlgorithm.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java index 842335ddd6b..b07da6e1747 100644 --- a/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java +++ b/sootup.callgraph/src/main/java/sootup/callgraph/AbstractCallGraphAlgorithm.java @@ -313,17 +313,21 @@ protected abstract void postProcessingMethod( @Nonnull @Override public CallGraph addClass(@Nonnull CallGraph oldCallGraph, @Nonnull JavaClassType classType) { - MutableCallGraph updated = oldCallGraph.copy(); - SootClass clazz = view.getClassOrThrow(classType); Set newMethodSignatures = - clazz.getMethods().stream().map(Method::getSignature).collect(Collectors.toSet()); + clazz.getMethods().stream() + .map(Method::getSignature) + .filter(methodSig -> !oldCallGraph.containsMethod(methodSig)) + .collect(Collectors.toSet()); - if (newMethodSignatures.stream().anyMatch(oldCallGraph::containsMethod)) { - // FIXME: [ms] handle better - remove from entry point signatures in this case - throw new IllegalArgumentException("CallGraph already contains methods from " + classType); + // were all the added method signatures already visited in the CallGraph? i.e. is there + // something to add? + if (newMethodSignatures.isEmpty()) { + return oldCallGraph; } + MutableCallGraph updated = oldCallGraph.copy(); + // Step 1: Add edges from the new methods to other methods Deque workList = new ArrayDeque<>(newMethodSignatures); Set processed = new HashSet<>(oldCallGraph.getMethodSignatures());