From 3d7a38c310545dce0e3ee87f6f4ef6e2d27dfc93 Mon Sep 17 00:00:00 2001 From: Markus Schmidt Date: Fri, 3 Nov 2023 14:48:33 +0100 Subject: [PATCH] add test input and enable interceptors --- .../bugfixes/Issue739_Aggregator.java | 9 +++++++ .../bytecode/interceptors/AggregatorTest.java | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 shared-test-resources/bugfixes/Issue739_Aggregator.java diff --git a/shared-test-resources/bugfixes/Issue739_Aggregator.java b/shared-test-resources/bugfixes/Issue739_Aggregator.java new file mode 100644 index 00000000000..4da5eb5cbb8 --- /dev/null +++ b/shared-test-resources/bugfixes/Issue739_Aggregator.java @@ -0,0 +1,9 @@ +public class Issue739_Aggregator { + public static void main(String[] args) { + int a = Integer.valueOf(args[0]); + int b = a; + int c = b; + System.out.println(a + b + c); + + } +} \ No newline at end of file diff --git a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java index 82b3a36b963..0114e4b554a 100644 --- a/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java +++ b/sootup.java.bytecode/src/test/java/sootup/java/bytecode/interceptors/AggregatorTest.java @@ -2,9 +2,11 @@ import static org.junit.Assert.assertEquals; +import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Set; +import org.junit.Assert; import org.junit.Test; import sootup.core.graph.MutableStmtGraph; import sootup.core.inputlocation.AnalysisInputLocation; @@ -18,9 +20,13 @@ import sootup.core.jimple.common.stmt.Stmt; import sootup.core.model.Body; import sootup.core.model.SootMethod; +import sootup.core.model.SourceType; +import sootup.core.types.ClassType; import sootup.core.types.PrimitiveType; import sootup.core.util.ImmutableUtils; +import sootup.java.bytecode.inputlocation.BytecodeClassLoadingOptions; import sootup.java.bytecode.inputlocation.JavaClassPathAnalysisInputLocation; +import sootup.java.bytecode.inputlocation.PathBasedAnalysisInputLocation; import sootup.java.core.JavaIdentifierFactory; import sootup.java.core.JavaProject; import sootup.java.core.JavaSootClass; @@ -177,4 +183,24 @@ public void testResource_Misuse() { System.out.println(sootMethod.getBody()); } } + + @Test + public void testIssue739() { + + PathBasedAnalysisInputLocation inputLocation = + PathBasedAnalysisInputLocation.create( + Paths.get("../shared-test-resources/bugfixes/Issue739_Aggregator.class"), + SourceType.Application); + + JavaProject project = + JavaProject.builder(new JavaLanguage(8)).addInputLocation(inputLocation).build(); + + JavaView view = project.createView(); + view.configBodyInterceptors(a -> BytecodeClassLoadingOptions.Default); + + final ClassType classType = view.getIdentifierFactory().getClassType("Issue739_Aggregator"); + Assert.assertTrue(view.getClass(classType).isPresent()); + + view.getClasses().stream().findFirst().get().getMethods().forEach(SootMethod::getBody); + } }