Code with Finding: |
class InstConstraintVisitor {
/**
* Ensures the specific preconditions of the said instruction.
*/
@Override
public void visitATHROW(ATHROW o){
try {
// It's stated that 'objectref' must be of a ReferenceType --- but since Throwable is
// not derived from an ArrayType, it follows that 'objectref' must be of an ObjectType or Type.NULL.
if (! ((stack().peek() instanceof ObjectType) || (stack().peek().equals(Type.NULL))) ){
constraintViolated(o, "The 'objectref' is not of an (initialized) ObjectType but of type "+stack().peek()+".");
}
// NULL is a subclass of every class, so to speak.
if (stack().peek().equals(Type.NULL)) {
return;
}
ObjectType exc = (ObjectType) (stack().peek());
ObjectType throwable = (ObjectType) (Type.getType("Ljava/lang/Throwable;"));
if ( (! (exc.subclassOf(throwable)) ) && (! (exc.equals(throwable))) ){
constraintViolated(o,
"The 'objectref' is not of class Throwable or of a subclass of Throwable, but of '"+stack().peek()+"'.");
}
} catch (ClassNotFoundException e) {
// FIXME: maybe not the best way to handle this
throw new AssertionViolatedException("Missing class: " + e, e);
}
}
}
class InstConstraintVisitor {
/**
* Ensures the specific preconditions of the said instruction.
*/
@Override
public void visitLDC2_W(LDC2_W o){
// visitCPInstruction is called first.
Constant c = cpg.getConstant(o.getIndex());
if (! ( ( c instanceof ConstantLong) ||
( c instanceof ConstantDouble ) ) ){
constraintViolated(o,
"Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'.");
}
}
}
|