Package org.apache.bcel.verifier.exc

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


      checkIndex(obj, obj.getClassIndex(), CONST_Class);
      checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
    }
    public void visitConstantInterfaceMethodref(ConstantInterfaceMethodref obj){
      if (obj.getTag() != Constants.CONSTANT_InterfaceMethodref){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      checkIndex(obj, obj.getClassIndex(), CONST_Class);
      checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
    }
View Full Code Here


      checkIndex(obj, obj.getClassIndex(), CONST_Class);
      checkIndex(obj, obj.getNameAndTypeIndex(), CONST_NameAndType);
    }
    public void visitConstantString(ConstantString obj){
      if (obj.getTag() != Constants.CONSTANT_String){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      checkIndex(obj, obj.getStringIndex(), CONST_Utf8);
    }
View Full Code Here

      }
      checkIndex(obj, obj.getStringIndex(), CONST_Utf8);
    }
    public void visitConstantInteger(ConstantInteger obj){
      if (obj.getTag() != Constants.CONSTANT_Integer){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      // no indices to check
    }
View Full Code Here

      }
      // no indices to check
    }
    public void visitConstantFloat(ConstantFloat obj){
      if (obj.getTag() != Constants.CONSTANT_Float){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      //no indices to check
    }
View Full Code Here

      }
      //no indices to check
    }
    public void visitConstantLong(ConstantLong obj){
      if (obj.getTag() != Constants.CONSTANT_Long){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      //no indices to check
    }
View Full Code Here

      }
      //no indices to check
    }
    public void visitConstantDouble(ConstantDouble obj){
      if (obj.getTag() != Constants.CONSTANT_Double){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      //no indices to check
    }
View Full Code Here

      }
      //no indices to check
    }
    public void visitConstantNameAndType(ConstantNameAndType obj){
      if (obj.getTag() != Constants.CONSTANT_NameAndType){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      checkIndex(obj, obj.getNameIndex(), CONST_Utf8);
      //checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below.
      checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
    }
View Full Code Here

      //checkIndex(obj, obj.getDescriptorIndex(), CONST_Utf8); //inconsistently named in BCEL, see below.
      checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);
    }
    public void visitConstantUtf8(ConstantUtf8 obj){
      if (obj.getTag() != Constants.CONSTANT_Utf8){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      //no indices to check
    }
View Full Code Here

                }
        if (obj.isPublic()) {
                    maxone++;
                }
        if (maxone > 1){
          throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC modifiers set.");
        }

        if (obj.isFinal() && obj.isVolatile()){
          throw new ClassConstraintException("Field '"+tostring(obj)+"' must only have at most one of its ACC_FINAL, ACC_VOLATILE modifiers set.");
        }
      }
      else{ // isInterface!
        if (!obj.isPublic()){
          throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_PUBLIC modifier set but hasn't!");
        }
        if (!obj.isStatic()){
          throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_STATIC modifier set but hasn't!");
        }
        if (!obj.isFinal()){
          throw new ClassConstraintException("Interface field '"+tostring(obj)+"' must have the ACC_FINAL modifier set but hasn't!");
        }
      }

      if ((obj.getAccessFlags() & ~(ACC_PUBLIC|ACC_PRIVATE|ACC_PROTECTED|ACC_STATIC|ACC_FINAL|ACC_VOLATILE|ACC_TRANSIENT)) > 0){
        addMessage("Field '"+tostring(obj)+"' has access flag(s) other than ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_VOLATILE, ACC_TRANSIENT set (ignored).");
      }

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

      String name = obj.getName();
      if (! validFieldName(name)){
        throw new ClassConstraintException("Field '"+tostring(obj)+"' has illegal name '"+obj.getName()+"'.");
      }

      // A descriptor is often named signature in BCEL
      checkIndex(obj, obj.getSignatureIndex(), CONST_Utf8);

      String sig  = ((ConstantUtf8) (cp.getConstant(obj.getSignatureIndex()))).getBytes(); // Field or Method signature(=descriptor)

      try{
        Type.getType(sig)/* Don't need the return value */
      }
      catch (ClassFormatException cfe){
                throw new ClassConstraintException("Illegal descriptor (==signature) '"+sig+"' used by '"+tostring(obj)+"'.");
      }

      String nameanddesc = (name+sig);
      if (field_names_and_desc.contains(nameanddesc)){
        throw new ClassConstraintException("No two fields (like '"+tostring(obj)+"') are allowed have same names and descriptors!");
      }
      if (field_names.contains(name)){
        addMessage("More than one field of name '"+name+"' detected (but with different type descriptors). This is very unusual.");
      }
      field_names_and_desc.add(nameanddesc);
View Full Code Here

      carrier.visit();
    }

    private void checkIndex(Node referrer, int index, Class<?> shouldbe){
      if ((index < 0) || (index >= cplen)){
        throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(referrer)+"'.");
      }
      Constant c = cp.getConstant(index);
      if (! shouldbe.isInstance(c)){
        /* String isnot = shouldbe.toString().substring(shouldbe.toString().lastIndexOf(".")+1); //Cut all before last "." */
        throw new ClassCastException("Illegal constant '"+tostring(c)+"' at index '"+index+"'. '"+tostring(referrer)+"' expects a '"+shouldbe+"'.");
View Full Code Here

TOP

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

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.