Skip to content

Commit

Permalink
added testcase for incomplete concreteDispatch in which the concrete …
Browse files Browse the repository at this point in the history
…method is in the missing class. Changed the test to use the bytecode frontend
  • Loading branch information
JonasKlauke committed Nov 17, 2023
1 parent 3113dcf commit a75d56e
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,17 @@ public static Optional<MethodSignature> resolveConcreteDispatch(
public static Optional<? extends SootMethod> findConcreteMethod(
@Nonnull View<? extends SootClass<?>> view, @Nonnull MethodSignature sig) {
IdentifierFactory identifierFactory = view.getIdentifierFactory();
Optional<? extends SootMethod> startMethod = view.getMethod(sig);
SootClass<?> startclass = view.getClass(sig.getDeclClassType()).orElse(null);
if (startclass == null) {
logger.warn(
"Could not find \""
+ sig.getDeclClassType()
+ "\" of method"
+ sig
+ " to resolve the concrete method");
return Optional.empty();
}
Optional<? extends SootMethod> startMethod = startclass.getMethod(sig.getSubSignature());
if (startMethod.isPresent()) {
return startMethod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import sootup.java.core.JavaProject;
import sootup.java.core.language.JavaLanguage;
import sootup.java.core.views.JavaView;
import sootup.java.sourcecode.inputlocation.JavaSourcePathAnalysisInputLocation;

/** @author : Hasitha Rajapakse, Jonas Klauke * */
@Category(Java8Test.class)
Expand All @@ -34,8 +33,8 @@ public static void setUp() {
JavaProject project =
JavaProject.builder(new JavaLanguage(8))
.addInputLocation(
new JavaSourcePathAnalysisInputLocation(
Collections.singleton("src/test/resources/callgraph/ConcreteDispatch/")))
new JavaClassPathAnalysisInputLocation(
"src/test/resources/callgraph/ConcreteDispatch/binary"))
.addInputLocation(
new JavaClassPathAnalysisInputLocation(
System.getProperty("java.home") + "/lib/rt.jar"))
Expand All @@ -46,20 +45,25 @@ public static void setUp() {
@Test
public void invalidResolveConcreteDispatch() {
IdentifierFactory factory = view.getIdentifierFactory();
Optional<MethodSignature> ms =
Optional<MethodSignature> incompleteMethod =
AbstractCallGraphAlgorithm.resolveConcreteDispatch(
view, factory.parseMethodSignature("java.util.Collection#size(): int"));
assertFalse(ms.isPresent());
view, factory.parseMethodSignature("cvcscincomplete.Class#target(): void"));
assertFalse(incompleteMethod.isPresent());
}

@Test()
public void invalidResolveConcreteDispatchOfAbstractMethod() {
IdentifierFactory factory = view.getIdentifierFactory();
Optional<MethodSignature> ms =
Optional<MethodSignature> abstractMethod =
AbstractCallGraphAlgorithm.resolveConcreteDispatch(
view,
factory.parseMethodSignature("java.util.AbstractList#get(int): java.lang.Object"));
assertFalse(ms.isPresent());
assertFalse(abstractMethod.isPresent());

Optional<MethodSignature> interfaceMethod =
AbstractCallGraphAlgorithm.resolveConcreteDispatch(
view, factory.parseMethodSignature("java.util.Collection#size(): int"));
assertFalse(interfaceMethod.isPresent());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// cvc/Class.java
package cvcscincomplete;

class Class extends SuperClass{

public static void main(String[] args){
Class cls = new Class();
cls.target();
}
}

//class file of the superclass is not in the inputlocation
class SuperClass {

public void target(){ }

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit a75d56e

Please sign in to comment.