Example usage for org.apache.commons.bcel6.verifier.exc VerifierConstraintViolatedException extendMessage

List of usage examples for org.apache.commons.bcel6.verifier.exc VerifierConstraintViolatedException extendMessage

Introduction

In this page you can find the example usage for org.apache.commons.bcel6.verifier.exc VerifierConstraintViolatedException extendMessage.

Prototype

public void extendMessage(String pre, String post) 

Source Link

Document

Extends the error message with a string before ("pre") and after ("post") the 'old' error message.

Usage

From source file:daikon.dcomp.StackVer.java

/**
 * Implements the pass 3b data flow analysis as described in the
 * Java Virtual Machine Specification, Second Edition.  As it is doing
 * so it keeps track of the stack and local variables at each instruction.
 *
 * @see org.apache.commons.bcel6.verifier.statics.Pass2Verifier#getLocalVariablesInfo(int)
 *///  www. ja  va2 s  . com
public VerificationResult do_stack_ver(MethodGen mg) {

    /*
      if (! myOwner.doPass3a(method_no).equals(VerificationResult.VR_OK)){
          return VerificationResult.VR_NOTYET;
      }
    */
    // Pass 3a ran before, so it's safe to assume the JavaClass object is
    // in the BCEL repository.
    // JavaClass jc = Repository.lookupClass(myOwner.getClassName());

    ConstantPoolGen constantPoolGen = mg.getConstantPool();
    // Init Visitors
    InstConstraintVisitor icv = new LimitedConstraintVisitor();
    icv.setConstantPoolGen(constantPoolGen);

    ExecutionVisitor ev = new ExecutionVisitor();
    ev.setConstantPoolGen(constantPoolGen);

    try {
        stack_types = new StackTypes(mg);

        icv.setMethodGen(mg);

        ////////////// DFA BEGINS HERE ////////////////
        if (!(mg.isAbstract() || mg.isNative())) { // IF mg HAS CODE (See pass 2)

            // false says don't check if jsr subroutine is covered by exception handler
            ControlFlowGraph cfg = new ControlFlowGraph(mg, false);

            // Build the initial frame situation for this method.
            Frame f = new Frame(mg.getMaxLocals(), mg.getMaxStack());
            if (!mg.isStatic()) {
                if (mg.getName().equals(Const.CONSTRUCTOR_NAME)) {
                    Frame.setThis(new UninitializedObjectType(new ObjectType(mg.getClassName())));
                    f.getLocals().set(0, Frame.getThis());
                } else {
                    @SuppressWarnings("nullness")
                    // unannotated: org.apache.commons.bcel6.verifier.structurals.Frame is not yet annotated
                    /*@NonNull*/ UninitializedObjectType dummy = null;
                    Frame.setThis(dummy);
                    f.getLocals().set(0, new ObjectType(mg.getClassName()));
                }
            }
            Type[] argtypes = mg.getArgumentTypes();
            int twoslotoffset = 0;
            for (int j = 0; j < argtypes.length; j++) {
                if (argtypes[j] == Type.SHORT || argtypes[j] == Type.BYTE || argtypes[j] == Type.CHAR
                        || argtypes[j] == Type.BOOLEAN) {
                    argtypes[j] = Type.INT;
                }
                f.getLocals().set(twoslotoffset + j + (mg.isStatic() ? 0 : 1), argtypes[j]);
                if (argtypes[j].getSize() == 2) {
                    twoslotoffset++;
                    f.getLocals().set(twoslotoffset + j + (mg.isStatic() ? 0 : 1), Type.UNKNOWN);
                }
            }
            circulationPump(cfg, cfg.contextOf(mg.getInstructionList().getStart()), f, icv, ev);
        }
    } catch (VerifierConstraintViolatedException ce) {
        ce.extendMessage("Constraint violated in method '" + mg + "':\n", "");
        return new VerificationResult(VerificationResult.VERIFIED_REJECTED, ce.getMessage());
    } catch (RuntimeException re) {
        // These are internal errors

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        re.printStackTrace(pw);

        throw new AssertionViolatedException(
                "Some RuntimeException occured while verify()ing class '" + mg.getClassName() + "', method '"
                        + mg + "'. Original RuntimeException's stack trace:\n---\n" + sw + "---\n");
    }
    return VerificationResult.VR_OK;
}