Package org.apache.bcel.verifier.exc

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


    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


   */
  public Subroutine getSubroutine(InstructionHandle leader){
    Subroutine ret = (Subroutine) subroutines.get(leader);
   
    if (ret == null){
      throw new AssertionViolatedException("Subroutine requested for an InstructionHandle that is not a leader of a subroutine.");
    }

    if (ret == TOPLEVEL){
      throw new AssertionViolatedException("TOPLEVEL special subroutine requested; use getTopLevel().");
    }
   
    return ret;
  }
View Full Code Here

    private int max_locals(){
       try {
      return Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getCode().getMaxLocals();
        } catch (ClassNotFoundException e) {
      // FIXME: maybe not the best way to handle this
      throw new AssertionViolatedException("Missing class: " + e.toString());
        }
    }
View Full Code Here

      }
      try{
        indexValid(o, o.getIndex()+1);
      }
      catch(StaticCodeInstructionOperandConstraintException e){
        throw new AssertionViolatedException("OOPS: Does not BCEL handle that? LDC2_W operand has a problem.");
      }
    }
View Full Code Here

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

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

      if (f.isFinal()){
        if (!(myOwner.getClassName().equals(o.getClassType(cpg).getClassName()))){
          constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getClassType(cpg).getClassName()+"'.");
        }
      }

      if (! (f.isStatic())){
        constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
      }

      String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName();

      // If it's an interface, it can be set only in <clinit>.
      if ((!(jc.isClass())) && (!(meth_name.equals(Constants.STATIC_INITIALIZER_NAME)))){
        constraintViolated(o, "Interface field '"+f+"' must be set in a '"+Constants.STATIC_INITIALIZER_NAME+"' method.");
      }
        } catch (ClassNotFoundException e) {
      // FIXME: maybe not the best way to handle this
      throw new AssertionViolatedException("Missing class: " + e.toString());
        }
    }
View Full Code Here

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

      if (! (f.isStatic())){
        constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
      }
        } catch (ClassNotFoundException e) {
      // FIXME: maybe not the best way to handle this
      throw new AssertionViolatedException("Missing class: " + e.toString());
        }
    }
View Full Code Here

      if (jc.isClass()){
        constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is a class, but not an interface as expected.");
      }
        } catch (ClassNotFoundException e) {
      // FIXME: maybe not the best way to handle this
      throw new AssertionViolatedException("Missing class: " + e.toString());
        }
    }
View Full Code Here

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

        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset.");
      }
   
        } 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.