[英]Soot: soot.jimple.JimpleBody cannot be cast to soot.dava.DavaBody
I ran the following code to get the exception handler in .class file: 我运行以下代码来获取.class文件中的异常处理程序:
public void getException(SootMethod method){
DavaBody db = (DavaBody) method.retrieveActiveBody();
IterableSet excepFacts = db.get_ExceptionFacts();
Iterator<ExceptionNode> it = excepFacts.iterator();
while(it.hasNext()){
ExceptionNode en = it.next();
...
}
}
I got errors after running above code: 运行以上代码后出现错误:
Exception in thread "main" java.lang.ClassCastException:
soot.jimple.JimpleBody cannot be cast to soot.dava.DavaBody
The method method.retrieveActiveBody()
returns Body type, not JimpleBody , so why is this error happening? 方法
method.retrieveActiveBody()
返回Body类型,而不是JimpleBody ,那么为什么会发生此错误?
Body is the declared type. 主体是声明的类型。 In your configuration of Soot, it actually returns a JimpleBody.
在您配置的Soot中,它实际上返回一个JimpleBody。
By the documentation , public Body retrieveActiveBody()
is: 根据文档 ,
public Body retrieveActiveBody()
为:
Returns the active body if present, else constructs an active body and returns that.
返回活动主体(如果存在),否则构造一个活动主体并将其返回。
Let's look at the Body
class: 让我们看一下
Body
类:
public abstract class Body
extends AbstractHost
implements Serializable
So it is Abstract
class, and by your exception, it returns JimpleBody
, subclass of Body
. 因此它是
Abstract
类,并且根据您的异常,它返回Body
子类JimpleBody
。
If Rabbit
is Animal
, and Wolf
is also Animal
, Rabbit
is not a Wolf
. 如果
Rabbit
是Animal
, Wolf
也是Animal
,那么Rabbit
不是Wolf
。
You can edit code like that: 您可以像这样编辑代码:
if (method.retrieveActiveBody() instanceof JimpleBody) {
} else if (method.retrieveActiveBody() instanceof DavaBody) {
} else if (method.retrieveActiveBody() instanceof BafBody) {
} else if (method.retrieveActiveBody() instanceof StmtBody) {
} else {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.