Describe the bug
In the case of nested IF expressions, the outer second IF expression fetches the wrong lineNumber, mistakenly taking the lineNumber of the first IF.
public static void main(String[] args) {
Options.v().set_src_prec(Options.src_prec_class);
Options.v().set_keep_line_number(true);
String classpath = System.getProperty("java.class.path");
Options.v().set_soot_classpath(classpath);
String classPath = "org.example.IfClass";
Scene.v().loadClassAndSupport(classPath);
Scene.v().loadNecessaryClasses();
SootClass sc = Scene.v().getSootClass("org.example.IfClass");
SootMethod sm = sc.getMethodByName("print");
Body b = sm.retrieveActiveBody();
for (Unit u : b.getUnits()) {
if (u instanceof IfStmt) {
IfStmt is = (IfStmt) u;
System.out.println("line:[" + is.getTags().get(0) + "] " + is.toString());
}
}
}
IfClass
public void print(int score, String name) {
if (score >= 90) {
String aaa = "";
if (!name.equals("admin")) {
aaa = name;
} else {
aaa = "mute";
}
System.out.println(aaa + ":A");
} else if (score >= 80) {
System.out.println("B");
} else if (score >= 70) {
System.out.println("C");
}
}
To reproduce
Steps to reproduce the behavior:
Attached is a complete Java Maven project demonstrating the bug (it can only run in a Java 8 environment). Open it using IntelliJ IDEA and run it directly to demonstrate the issue I want to convey.
After running the project, the following information will be printed:
line:[9] if i0 < 90 goto (branch)
line:[11] if $z0 != 0 goto r9 = "mute"
line:[9] if i0 < 80 goto (branch)
line:[19] if i0 < 70 goto return
Expected behavior
I expect the expression if (score >= 80) to correctly display lineNumber 17.
Describe the bug In the case of nested IF expressions, the outer second IF expression fetches the wrong lineNumber, mistakenly taking the lineNumber of the first IF.
Input file sootbug.zip
The main code in sootbug.zip
IfClass
To reproduce Steps to reproduce the behavior:
Expected behavior I expect the expression if (score >= 80) to correctly display lineNumber 17.
Stacktrace
Additional context Thank you very much