Skip to content

Commit

Permalink
add test input and enable interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
swissiety committed Nov 3, 2023
1 parent 1007485 commit 3d7a38c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions shared-test-resources/bugfixes/Issue739_Aggregator.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3d7a38c

Please sign in to comment.