From 6080645772bf6f7c4095be0ac89572dad7b4738b Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Sat, 7 Dec 2024 23:25:52 +0800 Subject: [PATCH 1/2] remove Optional since buildClassFrom always builds a class --- .../java/sootup/java/core/views/JavaModuleView.java | 6 +++--- .../src/main/java/sootup/java/core/views/JavaView.java | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java index bf0187d8523..db2de980c38 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java @@ -163,7 +163,7 @@ public synchronized Optional getClass( if (!foundClassSources.isEmpty()) { - return buildClassFrom(foundClassSources.get(0)); + return Optional.of(buildClassFrom(foundClassSources.get(0))); } else { PackageName packageName = type.getPackageName(); if (packageName instanceof ModulePackageName @@ -189,7 +189,7 @@ public synchronized Optional getClass( .collect(Collectors.toList()); if (!foundClassSources.isEmpty()) { - return buildClassFrom(foundClassSources.get(0)); + return Optional.of(buildClassFrom(foundClassSources.get(0))); } else { // automatic module can access the unnamed module -> try to find in classpath (as if // modules do not exist) @@ -231,7 +231,7 @@ public synchronized Optional getClass( }) .findAny(); - return foundClassSources.flatMap(this::buildClassFrom); + return foundClassSources.map(this::buildClassFrom); } } diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java index 4ec1a592bc3..54a0c032ca4 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaView.java @@ -88,9 +88,7 @@ public synchronized Stream getClasses() { Stream resolvedClasses = inputLocations.stream() .flatMap(location -> location.getClassSources(this).stream()) - .map(this::buildClassFrom) - .filter(Optional::isPresent) - .map(Optional::get); + .map(this::buildClassFrom); isFullyResolved = true; @@ -107,7 +105,7 @@ public synchronized Optional getClass(@Nonnull ClassType type) { } Optional abstractClass = getClassSource(type); - return abstractClass.flatMap(this::buildClassFrom); + return abstractClass.map(this::buildClassFrom); } @Nonnull @@ -155,7 +153,7 @@ protected Optional getClassSource(@Nonnull ClassType type) } @Nonnull - protected synchronized Optional buildClassFrom(AbstractClassSource classSource) { + protected synchronized JavaSootClass buildClassFrom(AbstractClassSource classSource) { ClassType classType = classSource.getClassType(); JavaSootClass theClass; @@ -167,6 +165,6 @@ protected synchronized Optional buildClassFrom(AbstractClassSourc classSource.buildClass(classSource.getAnalysisInputLocation().getSourceType()); cache.putClass(classType, theClass); } - return Optional.of(theClass); + return theClass; } } From 6be6234b4714ebce5a7a4d20a79caea78042e21a Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Sat, 7 Dec 2024 23:28:53 +0800 Subject: [PATCH 2/2] fix --- .../main/java/sootup/java/core/views/JavaModuleView.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java index db2de980c38..9a057a9e237 100644 --- a/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java +++ b/sootup.java.core/src/main/java/sootup/java/core/views/JavaModuleView.java @@ -333,11 +333,7 @@ public synchronized Collection getModuleClasses( .map(src -> (JavaSootClassSource) src)); } } - return stream - .map(this::buildClassFrom) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); + return stream.map(this::buildClassFrom).collect(Collectors.toList()); } /*