From 1ec5b1256639b21b4f6249de2918694386723f03 Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 8 Sep 2023 10:57:35 +0200 Subject: [PATCH 1/2] adapted incompleteSuperclassesOf to the new thrown exception in the class resolving method --- .../src/main/java/sootup/core/typehierarchy/TypeHierarchy.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java index 6e70a97ae20..5efed1cff0c 100644 --- a/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java +++ b/sootup.core/src/main/java/sootup/core/typehierarchy/TypeHierarchy.java @@ -28,7 +28,6 @@ import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import sootup.core.frontend.ResolveException; import sootup.core.types.*; import sootup.core.views.View; @@ -198,7 +197,7 @@ default List incompleteSuperClassesOf(@Nonnull ClassType classType) { superClasses.add(currentSuperClass); currentSuperClass = superClassOf(currentSuperClass); } - } catch (ResolveException ex) { + } catch (IllegalArgumentException ex) { logger.warn( "Could not find " + (currentSuperClass != null ? currentSuperClass : classType) From 32f856e4189f79471d1f6b7daa449b0a0f423d3a Mon Sep 17 00:00:00 2001 From: Jonas Klauke Date: Fri, 8 Sep 2023 11:39:38 +0200 Subject: [PATCH 2/2] added test case for incomplete Superclasses --- .../IncompleteSuperclassTest.java | 31 +++++++++++++++++++ .../IncompleteSuperclass/SubClassA.java | 3 ++ .../IncompleteSuperclass/SubClassB.java | 3 ++ 3 files changed, 37 insertions(+) create mode 100644 sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java create mode 100644 sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java create mode 100644 sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java diff --git a/sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java b/sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java new file mode 100644 index 00000000000..c51a52b0a8f --- /dev/null +++ b/sootup.tests/src/test/java/sootup/tests/typehierarchy/viewtypehierarchytestcase/IncompleteSuperclassTest.java @@ -0,0 +1,31 @@ +package sootup.tests.typehierarchy.viewtypehierarchytestcase; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static sootup.core.util.ImmutableUtils.immutableList; + +import categories.Java8Test; +import com.google.common.collect.ImmutableList; +import java.util.List; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import sootup.core.typehierarchy.ViewTypeHierarchy; +import sootup.core.types.ClassType; +import sootup.tests.typehierarchy.JavaTypeHierarchyTestBase; + +/** @author Jonas Klauke * */ +@Category(Java8Test.class) +public class IncompleteSuperclassTest extends JavaTypeHierarchyTestBase { + @Test + public void method() { + ViewTypeHierarchy typeHierarchy = + (ViewTypeHierarchy) customTestWatcher.getView().getTypeHierarchy(); + List superclasses = + typeHierarchy.incompleteSuperClassesOf(getClassType("SubClassB")); + ClassType object = getClassType("java.lang.Object"); + ImmutableList expectedSuperClasses = + immutableList(getClassType("SubClassA"), object); + assertEquals(expectedSuperClasses, superclasses); + assertFalse(customTestWatcher.getView().getClass(object).isPresent()); + } +} diff --git a/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java new file mode 100644 index 00000000000..b3301dd276e --- /dev/null +++ b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassA.java @@ -0,0 +1,3 @@ +public class SubClassA { + +} \ No newline at end of file diff --git a/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java new file mode 100644 index 00000000000..d278f9127fc --- /dev/null +++ b/sootup.tests/src/test/resources/javatypehierarchy/IncompleteSuperclass/SubClassB.java @@ -0,0 +1,3 @@ +public class SubClassB extends SubClassA { + +} \ No newline at end of file