Package org.apache.bcel.verifier.exc

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


                // 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()) + "'?");
                }
View Full Code Here


            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
View Full Code Here

  /**
   * Pushes a Type object onto the stack.
   */
  public void push(Type type){
    if (type == null) {
            throw new AssertionViolatedException("Cannot push NULL onto OperandStack.");
        }
    if (type == Type.BOOLEAN || type == Type.CHAR || type == Type.BYTE || type == Type.SHORT){
      throw new AssertionViolatedException("The OperandStack does not know about '"+type+"'; use Type.INT instead.");
    }
    if (slotsUsed() >= maxStack){
      throw new AssertionViolatedException("OperandStack too small, should have thrown proper Exception elsewhere. Stack: "+this);
    }
    stack.add(type);
  }
View Full Code Here

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

  /**
   * Sets a new Type for the given local variable slot.
   */
  public void set(int i, Type type){
    if (type == Type.BYTE || type == Type.SHORT || type == Type.BOOLEAN || type == Type.CHAR){
      throw new AssertionViolatedException("LocalVariables do not know about '"+type+"'. Use Type.INT instead.");
    }
    locals[i] = type;
  }
View Full Code Here

   * Second Edition, section 4.9.2, page 146.
   */
  public void merge(LocalVariables lv){

    if (this.locals.length != lv.locals.length){
      throw new AssertionViolatedException("Merging LocalVariables of different size?!? From different methods or what?!?");
    }

    for (int i=0; i<locals.length; i++){
      merge(lv, i);
    }
View Full Code Here

        if (sup != null){
          locals[i] = sup;
        }
        else{
          // We should have checked this in Pass2!
          throw new AssertionViolatedException("Could not load all the super classes of '"+locals[i]+"' and '"+lv.locals[i]+"'.");
        }
      }
    }
    else{
      if (! (locals[i].equals(lv.locals[i])) ){
/*TODO
        if ((locals[i] instanceof org.apache.bcel.generic.ReturnaddressType) && (lv.locals[i] instanceof org.apache.bcel.generic.ReturnaddressType)){
          //System.err.println("merging "+locals[i]+" and "+lv.locals[i]);
          throw new AssertionViolatedException("Merging different ReturnAddresses: '"+locals[i]+"' and '"+lv.locals[i]+"'.");
        }
*/
        locals[i] = Type.UNKNOWN;
      }
    }
      } catch (ClassNotFoundException e) {
    // FIXME: maybe not the best way to handle this
    throw new AssertionViolatedException("Missing class: " + e.toString(), e);
      }
  }
View Full Code Here

          method_number = mn;
          break;
        }
      }
      if (method_number < 0){ // Mmmmh. Can we be sure BCEL does not sometimes instantiate new objects?
        throw new AssertionViolatedException("Could not find a known BCEL Method object in the corresponding BCEL JavaClass object.");
      }
      localVariablesInfos[method_number] = new LocalVariablesInfo(obj.getMaxLocals());

      int num_of_lvt_attribs = 0;
      // Now iterate through the attributes the Code attribute has.
      Attribute[] atts = obj.getAttributes();
      for (int a=0; a<atts.length; a++){
        if ((! (atts[a] instanceof LineNumberTable)) &&
            (! (atts[a] instanceof LocalVariableTable))){
          addMessage("Attribute '"+tostring(atts[a])+"' as an attribute of Code attribute '"+tostring(obj)+"' (method '"+m+"') is unknown and will therefore be ignored.");
        }
        else{// LineNumberTable or LocalVariableTable
          addMessage("Attribute '"+tostring(atts[a])+"' as an attribute of Code attribute '"+tostring(obj)+"' (method '"+m+"') will effectively be ignored and is only useful for debuggers and such.");
        }

        //LocalVariableTable check (partially delayed to Pass3a).
        //Here because its easier to collect the information of the
        //(possibly more than one) LocalVariableTables belonging to
        //one certain Code attribute.
        if (atts[a] instanceof LocalVariableTable){ // checks conforming to vmspec2 4.7.9

          LocalVariableTable lvt = (LocalVariableTable) atts[a];

          checkIndex(lvt, lvt.getNameIndex(), CONST_Utf8);

          String lvtname = ((ConstantUtf8) cp.getConstant(lvt.getNameIndex())).getBytes();
          if (! lvtname.equals("LocalVariableTable")){
            throw new ClassConstraintException("The LocalVariableTable attribute '"+tostring(lvt)+"' is not correctly named 'LocalVariableTable' but '"+lvtname+"'.");
          }

          Code code = obj;

          //In JustIce, the check for correct offsets into the code array is delayed to Pass 3a.
          LocalVariable[] localvariables = lvt.getLocalVariableTable();

          for (int i=0; i<localvariables.length; i++){
            checkIndex(lvt, localvariables[i].getNameIndex(), CONST_Utf8);
            String localname = ((ConstantUtf8) cp.getConstant(localvariables[i].getNameIndex())).getBytes();
            if (!validJavaIdentifier(localname)){
              throw new ClassConstraintException("LocalVariableTable '"+tostring(lvt)+"' references a local variable by the name '"+localname+"' which is not a legal Java simple name.");
            }

            checkIndex(lvt, localvariables[i].getSignatureIndex(), CONST_Utf8);
            String localsig  = ((ConstantUtf8) (cp.getConstant(localvariables[i].getSignatureIndex()))).getBytes(); // Local signature(=descriptor)
            Type t;
            try{
              t = Type.getType(localsig);
            }
            catch (ClassFormatException cfe){
              throw new ClassConstraintException("Illegal descriptor (==signature) '"+localsig+"' used by LocalVariable '"+tostring(localvariables[i])+"' referenced by '"+tostring(lvt)+"'.", cfe);
            }
            int localindex = localvariables[i].getIndex();
            if ( ( (t==Type.LONG || t==Type.DOUBLE)? localindex+1:localindex) >= code.getMaxLocals()){
              throw new ClassConstraintException("LocalVariableTable attribute '"+tostring(lvt)+"' references a LocalVariable '"+tostring(localvariables[i])+"' with an index that exceeds the surrounding Code attribute's max_locals value of '"+code.getMaxLocals()+"'.");
            }

            try{
              localVariablesInfos[method_number].add(localindex, localname, localvariables[i].getStartPC(), localvariables[i].getLength(), t);
            }
            catch(LocalVariableInfoInconsistentException lviie){
              throw new ClassConstraintException("Conflicting information in LocalVariableTable '"+tostring(lvt)+"' found in Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"'). "+lviie.getMessage(), lviie);
            }
          }// for all local variables localvariables[i] in the LocalVariableTable attribute atts[a] END

          num_of_lvt_attribs++;
          if (!m.isStatic() && num_of_lvt_attribs > obj.getMaxLocals()){
            throw new ClassConstraintException("Number of LocalVariableTable attributes of Code attribute '"+tostring(obj)+"' (method '"+tostring(m)+"') exceeds number of local variable slots '"+obj.getMaxLocals()+"' ('There may be no more than one LocalVariableTable attribute per local variable in the Code attribute.').");
          }
        }// if atts[a] instanceof LocalVariableTable END
      }// for all attributes atts[a] END

        } catch (ClassNotFoundException e) {
      // FIXME: this might not be the best way to handle missing classes.
      throw new AssertionViolatedException("Missing class: " + e.toString(), e);
        }

    }// visitCode(Code) END
View Full Code Here

        }
      }

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

   * Returns the InstructionContext of a given instruction.
   */
  public InstructionContext contextOf(InstructionHandle inst){
    InstructionContext ic = instructionContexts.get(inst);
    if (ic == null){
      throw new AssertionViolatedException("InstructionContext requested for an InstructionHandle that's not known!");
    }
    return ic;
  }
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.