diff --git a/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java b/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java index 9cd15096eeb..1688ad7a273 100644 --- a/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java +++ b/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java @@ -907,6 +907,9 @@ public void removeNode(@Nonnull Stmt stmt, boolean keepFlow) { blockOfRemovedStmt.clearPredecessorBlocks(); blockOfRemovedStmt.clearSuccessorBlocks(); blockOfRemovedStmt.clearExceptionalSuccessorBlocks(); + + clearBlockFromAllExceptionalBlocks(blockOfRemovedStmt); + blockOfRemovedStmt.removeStmt(blockOfRemovedStmtPair.getLeft()); blocks.remove(blockOfRemovedStmt); @@ -976,6 +979,27 @@ public void removeNode(@Nonnull Stmt stmt, boolean keepFlow) { stmtToBlock.remove(stmt); } + public void clearBlockFromAllExceptionalBlocks(MutableBasicBlock blockOfRemovedStmt) { + // Remove blockOfRemovedStmt from all exceptionalBlocks in MutableBlockStmtGraph + for (Iterator iterator = blocks.iterator(); iterator.hasNext(); ) { + MutableBasicBlock block = iterator.next(); + Collection blockExceptionalSuccessors = + block.getExceptionalSuccessors().values(); + if (!blockExceptionalSuccessors.isEmpty()) { + for (MutableBasicBlock exceptionalBlock : blockExceptionalSuccessors) { + List exceptionalBlockSuccessors = exceptionalBlock.getSuccessors(); + List exceptionalBlockPredecessors = exceptionalBlock.getPredecessors(); + if (exceptionalBlockPredecessors.contains(blockOfRemovedStmt)) { + exceptionalBlock.removePredecessorBlock(blockOfRemovedStmt); + } + if (exceptionalBlockSuccessors.contains(blockOfRemovedStmt)) { + exceptionalBlock.removeFromSuccessorBlocks(blockOfRemovedStmt); + } + } + } + } + } + @Override public void replaceNode(@Nonnull Stmt oldStmt, @Nonnull Stmt newStmt) { if (oldStmt == newStmt) { diff --git a/sootup.java.bytecode.frontend/pom.xml b/sootup.java.bytecode.frontend/pom.xml index 2a6a65200af..c7be9014518 100644 --- a/sootup.java.bytecode.frontend/pom.xml +++ b/sootup.java.bytecode.frontend/pom.xml @@ -60,6 +60,11 @@ gson 2.8.9 - + + org.soot-oss + sootup.jimple.frontend + test + + diff --git a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/inputlocation/FixJars.java b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/inputlocation/FixJars.java new file mode 100644 index 00000000000..cdda50e5ea4 --- /dev/null +++ b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/inputlocation/FixJars.java @@ -0,0 +1,41 @@ +package sootup.java.bytecode.frontend.inputlocation; + +import categories.TestCategories; +import java.nio.file.Paths; +import java.util.Collections; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import sootup.core.inputlocation.AnalysisInputLocation; +import sootup.core.model.Body; +import sootup.core.model.SourceType; +import sootup.interceptors.NopEliminator; +import sootup.jimple.frontend.JimpleAnalysisInputLocation; +import sootup.jimple.frontend.JimpleView; + +@Tag(TestCategories.JAVA_8_CATEGORY) +public class FixJars extends BaseFixJarsTest { + + @Test + /* Isolated testcase from: + * String jarDownloadUrl = "https://repo1.maven.org/maven2/io/github/adven27/exam-core/2024.0.10/exam-core-2024.0.10.jar"; + * String methodSignature = ""; + */ + public void executeexamcorejar() { + AnalysisInputLocation inputLocation = + new JimpleAnalysisInputLocation( + Paths.get("./src/test/resources/"), + SourceType.Application, + Collections.singletonList(new NopEliminator())); + JimpleView jimpleView = new JimpleView(inputLocation); + jimpleView + .getClasses() + .forEach( + sootClass -> { + Body body = + sootClass.getMethodsByName("nopEliminatorBug").stream() + .findFirst() + .get() + .getBody(); + }); + } +} diff --git a/sootup.java.bytecode.frontend/src/test/resources/nopEliminatorBugTest.jimple b/sootup.java.bytecode.frontend/src/test/resources/nopEliminatorBugTest.jimple new file mode 100644 index 00000000000..ec1175ddfb0 --- /dev/null +++ b/sootup.java.bytecode.frontend/src/test/resources/nopEliminatorBugTest.jimple @@ -0,0 +1,43 @@ +class DummyClass extends java.lang.Object { + + public int nopEliminatorBug() { + this := @this: io.github.adven27.concordion.extensions.exam.core.logger.LoggingFormatterExtension$LoggingFormatterListener; + event := @parameter0: org.concordion.api.listener.ExampleEvent; + staticinvoke (event, "event"); + + label1: + nop; + $stack5 = this.; + it = interfaceinvoke $stack5.(); + $stack6 = virtualinvoke it.(); + + if $stack6 == 0 goto label2; + specialinvoke this.(event, it); + + label2: + nop; + nop; + + label3: + $stack7 = this.; + interfaceinvoke $stack7.(); + + goto label6; + + label4: + $stack8 := @caughtexception; + l2 = $stack8; + + label5: + $stack9 = this.; + interfaceinvoke $stack9.(); + + throw l2; + + label6: + return; + + catch java.lang.Throwable from label1 to label3 with label4; + catch java.lang.Throwable from label4 to label5 with label4; + } +}