Package org.apache.bcel.verifier.exc

Examples of org.apache.bcel.verifier.exc.AssertionViolatedException


            break;
          }
      }
    }
    if (f == null){
      throw new AssertionViolatedException("Field not found?!?");
    }

    Type value = stack().peek();
    Type t = Type.getType(f.getSignature());
    Type shouldbe = t;
    if (shouldbe == Type.BOOLEAN ||
        shouldbe == Type.BYTE ||
        shouldbe == Type.CHAR ||
        shouldbe == Type.SHORT){
      shouldbe = Type.INT;
    }
    if (t instanceof ReferenceType){
      ReferenceType rvalue = null;
      if (value instanceof ReferenceType){
        rvalue = (ReferenceType) value;
        referenceTypeIsInitialized(o, rvalue);
      }
      else{
        constraintViolated(o, "The stack top type '"+value+"' is not of a reference type as expected.");
      }
      // TODO: This can possibly only be checked using Staerk-et-al's "set-of-object types", not
      // using "wider cast object types" created during verification.
      // Comment it out if you encounter problems. See also the analogon at visitPUTSTATIC.
      if (!(rvalue.isAssignmentCompatibleWith(shouldbe))){
        constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
      }
    }
    else{
      if (shouldbe != value){
        constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
      }
    }
   
    if (f.isProtected()){
      ObjectType classtype = o.getClassType(cpg);
      ObjectType curr = new ObjectType(mg.getClassName());

      if classtype.equals(curr) ||
            curr.subclassOf(classtype)  ){
        Type tp = stack().peek(1);
        if (tp == Type.NULL){
          return;
        }
        if (! (tp instanceof ObjectType) ){
          constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+tp+"'.");
        }
        ObjectType objreftype = (ObjectType) tp;
        if (! ( objreftype.equals(curr) ||
                objreftype.subclassOf(curr) ) ){
          constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
        }
      }
    }

    // TODO: Could go into Pass 3a.
    if (f.isStatic()){
      constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
    }

      } catch (ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e.toString());
      }
  }
View Full Code Here


            break;
          }
      }
    }
    if (f == null){
      throw new AssertionViolatedException("Field not found?!?");
    }
    Type value = stack().peek();
    Type t = Type.getType(f.getSignature());
    Type shouldbe = t;
    if (shouldbe == Type.BOOLEAN ||
        shouldbe == Type.BYTE ||
        shouldbe == Type.CHAR ||
        shouldbe == Type.SHORT){
      shouldbe = Type.INT;
    }
    if (t instanceof ReferenceType){
      ReferenceType rvalue = null;
      if (value instanceof ReferenceType){
        rvalue = (ReferenceType) value;
        referenceTypeIsInitialized(o, rvalue);
      }
      else{
        constraintViolated(o, "The stack top type '"+value+"' is not of a reference type as expected.");
      }
      // TODO: This can possibly only be checked using Staerk-et-al's "set-of-object types", not
      // using "wider cast object types" created during verification.
      // Comment it out if you encounter problems. See also the analogon at visitPUTFIELD.
      if (!(rvalue.isAssignmentCompatibleWith(shouldbe))){
        constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
      }
    }
    else{
      if (shouldbe != value){
        constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
      }
    }
    // TODO: Interface fields may be assigned to only once. (Hard to implement in
    //       JustIce's execution model). This may only happen in <clinit>, see Pass 3a.

      } catch (ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e.toString());
      }
  }
View Full Code Here

  public void visitRET(RET o){
    if (! (locals().get(o.getIndex()) instanceof ReturnaddressType)){
      constraintViolated(o, "Expecting a ReturnaddressType in local variable "+o.getIndex()+".");
    }
    if (locals().get(o.getIndex()) == ReturnaddressType.NO_TARGET){
      throw new AssertionViolatedException("Oops: RET expecting a target!");
    }
    // Other constraints such as non-allowed overlapping subroutines are enforced
    // while building the Subroutines data structure.
  }
View Full Code Here

        // Sanity check
        InstructionContext lastJSR = null;
        int skip_jsr = 0;
        for (int ss=oldchain.size()-1; ss >= 0; ss--){
          if (skip_jsr < 0){
            throw new AssertionViolatedException("More RET than JSR in execution chain?!");
          }
//System.err.println("+"+oldchain.get(ss));
          if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction() instanceof JsrInstruction){
            if (skip_jsr == 0){
              lastJSR = (InstructionContext) oldchain.get(ss);
              break;
            }
            else{
              skip_jsr--;
            }
          }
          if (((InstructionContext) oldchain.get(ss)).getInstruction().getInstruction() instanceof RET){
            skip_jsr++;
          }
        }
        if (lastJSR == null){
          throw new AssertionViolatedException("RET without a JSR before in ExecutionChain?! EC: '"+oldchain+"'.");
        }
        JsrInstruction jsr = (JsrInstruction) (lastJSR.getInstruction().getInstruction());
        if ( theSuccessor != (cfg.contextOf(jsr.physicalSuccessor())) ){
          throw new AssertionViolatedException("RET '"+u.getInstruction()+"' info inconsistent: jump back to '"+theSuccessor+"' or '"+cfg.contextOf(jsr.physicalSuccessor())+"'?");
        }
       
        if (theSuccessor.execute(u.getOutFrame(oldchain), newchain, icv, ev)){
          icq.add(theSuccessor, (ArrayList) newchain.clone());
        }
View Full Code Here

    JavaClass jc;
    try {
      jc = Repository.lookupClass(myOwner.getClassName());
    } catch (ClassNotFoundException e) {
      // FIXME: maybe not the best way to handle this
      throw new AssertionViolatedException("Missing class: " + e.toString());
    }

    ConstantPoolGen constantPoolGen = new ConstantPoolGen(jc.getConstantPool());
    // Init Visitors
    InstConstraintVisitor icv = new InstConstraintVisitor();
    icv.setConstantPoolGen(constantPoolGen);
   
    ExecutionVisitor ev = new ExecutionVisitor();
    ev.setConstantPoolGen(constantPoolGen);
   
    Method[] methods = jc.getMethods(); // Method no "method_no" exists, we ran Pass3a before on it!

    try{

      MethodGen mg = new MethodGen(methods[method_no], myOwner.getClassName(), constantPoolGen);

      icv.setMethodGen(mg);
       
      ////////////// DFA BEGINS HERE ////////////////
      if (! (mg.isAbstract() || mg.isNative()) ){ // IF mg HAS CODE (See pass 2)
       
        ControlFlowGraph cfg = new ControlFlowGraph(mg);

        // Build the initial frame situation for this method.
        Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack());
        if ( !mg.isStatic() ){
          if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){
            Frame._this = new UninitializedObjectType(new ObjectType(jc.getClassName()));
            f.getLocals().set(0, Frame._this);
          }
          else{
            Frame._this = null;
            f.getLocals().set(0, new ObjectType(jc.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 '"+methods[method_no]+"':\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 '"+jc.getClassName()+"', method '"+methods[method_no]+"'. Original RuntimeException's stack trace:\n---\n"+sw+"---\n");
    }
    return VerificationResult.VR_OK;
  }
View Full Code Here

   * Ensures the general preconditions of a CPInstruction instance.
   */
  public void visitCPInstruction(CPInstruction o){
    int idx = o.getIndex();
    if ((idx < 0) || (idx >= cpg.getSize())){
      throw new AssertionViolatedException("Huh?! Constant pool index of instruction '"+o+"' illegal? Pass 3a should have checked this!");
    }
  }
View Full Code Here

        constraintViolated(o, "The type of 'value' ('"+value+"') is not assignment compatible to the components of the array 'arrayref' refers to. ('"+((ArrayType) arrayref).getElementType()+"')");
      }
    }
      } catch (ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e.toString());
      }
  }
View Full Code Here

    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.toString());
      }
  }
View Full Code Here

  /**
   * Ensures the specific preconditions of the said instruction.
   */
  public void visitBREAKPOINT(BREAKPOINT o){
    throw new AssertionViolatedException("In this JustIce verification pass there should not occur an illegal instruction such as BREAKPOINT.");
  }
View Full Code Here

            break;
          }
      }
    }
    if (f == null){
      throw new AssertionViolatedException("Field not found?!?");
    }

    if (f.isProtected()){
      ObjectType classtype = o.getClassType(cpg);
      ObjectType curr = new ObjectType(mg.getClassName());

      if classtype.equals(curr) ||
            curr.subclassOf(classtype)  ){
        Type t = stack().peek();
        if (t == Type.NULL){
          return;
        }
        if (! (t instanceof ObjectType) ){
          constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+t+"'.");
        }
        ObjectType objreftype = (ObjectType) t;
        if (! ( objreftype.equals(curr) ||
                objreftype.subclassOf(curr) ) ){
          //TODO: One day move to Staerk-et-al's "Set of object types" instead of "wider" object types
          //      created during the verification.
          //      "Wider" object types don't allow us to check for things like that below.
          //constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
        }
      }
    }
   
    // TODO: Could go into Pass 3a.
    if (f.isStatic()){
      constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
    }

      } catch (ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e.toString());
      }
  }
View Full Code Here

TOP

Related Classes of org.apache.bcel.verifier.exc.AssertionViolatedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.