Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeAssigner: ClassCastException: StringConstant cannot be cast to Local #1143

Open
swissiety opened this issue Dec 2, 2024 Discussed in #1142 · 1 comment
Open

TypeAssigner: ClassCastException: StringConstant cannot be cast to Local #1143

swissiety opened this issue Dec 2, 2024 Discussed in #1142 · 1 comment
Assignees

Comments

@swissiety
Copy link
Collaborator

Discussed in #1142

Originally posted by DHANUSHIYADEVI December 2, 2024
I am new to SootUp and trying to GET method body from a Soot class, but I'm encountering a ClassCastException for certain classes, as shown below:

		Set<JavaSootMethod> sootMethods = sootClass.getMethods();
		for (JavaSootMethod sootMethod : sootMethods) {
			System.out.println("Going to parse :: "+sootMethod.getSignature().toString());
			if (sootMethod.hasBody()) {
				Body body = sootMethod.getBody(); // Getting exception here
                          }
                }

Caused by: java.lang.ClassCastException: class sootup.core.jimple.common.constant.StringConstant cannot be cast to class sootup.core.jimple.basic.Local (sootup.core.jimple.common.constant.StringConstant and sootup.core.jimple.basic.Local are in unnamed module of loader 'app')
at sootup.java.core.interceptors.typeresolving.TypePromotionVisitor.visit(TypePromotionVisitor.java:76)
at sootup.java.core.interceptors.typeresolving.TypeChecker.handleInvokeExpr(TypeChecker.java:300)
at sootup.java.core.interceptors.typeresolving.TypeChecker.caseAssignStmt(TypeChecker.java:220)
at sootup.core.jimple.common.stmt.JAssignStmt.accept(JAssignStmt.java:201)
at sootup.core.jimple.common.stmt.JAssignStmt.accept(JAssignStmt.java:59)
at sootup.java.core.interceptors.typeresolving.TypePromotionVisitor.getPromotedTyping(TypePromotionVisitor.java:47)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1655)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578)
at sootup.java.core.interceptors.typeresolving.TypeResolver.resolve(TypeResolver.java:81)
at sootup.java.core.interceptors.TypeAssigner.interceptBody(TypeAssigner.java:42)
at sootup.java.bytecode.frontend.AsmMethodSource.resolveBody(AsmMethodSource.java:234)
... 8 more

Would greatly appreciate any confirmation or corrections, as I’m unsure why I’m getting a ClassCastException for only certain classes. Am I using the correct approach to retrieve the method body? I’m following the example provided in this link.

Thank you in advance for your time and assistance.

@sahilagichani14 sahilagichani14 self-assigned this Dec 8, 2024
@sahilagichani14
Copy link
Collaborator

I tried running the example:
1 parent pom file missing
2 SootUp version used is 1.1.2, please use latest version. Adjust imports according to the latest version
3 Output after applying DeadAssignmentEliminator is correct (removed assignment part)

{
File this;
unknown $stack2;
this := @this: File;
$stack2 = <java.lang.System: java.io.PrintStream out>;
virtualinvoke $stack2.<java.io.PrintStream: void println(int)>(3);
return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants