Package org.apache.bcel.verifier.exc

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


        if (atts[i] instanceof SourceFile){
          if (foundSourceFile == false) {
                        foundSourceFile = true;
                    } else {
                        throw new ClassConstraintException("A ClassFile structure (like '"+tostring(obj)+"') may have no more than one SourceFile attribute."); //vmspec2 4.7.7
                    }
        }

        if (atts[i] instanceof InnerClasses){
          if (foundInnerClasses == false) {
                        foundInnerClasses = true;
                    } else{
            if (hasInnerClass){
              throw new ClassConstraintException("A Classfile structure (like '"+tostring(obj)+"') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case). More than one InnerClasses attribute was found.");
            }
          }
          if (!hasInnerClass){
            addMessage("No referenced Inner Class found, but InnerClasses attribute '"+tostring(atts[i])+"' found. Strongly suggest removal of that attribute.");
          }
View Full Code Here


    // CONSTANTS (vmspec2 4.4) //
    /////////////////////////////
    @Override
        public void visitConstantClass(ConstantClass obj){
      if (obj.getTag() != Constants.CONSTANT_Class){
        throw new ClassConstraintException("Wrong constant tag in '"+tostring(obj)+"'.");
      }
      checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

    }
View Full Code Here

    }
    @Override
        public void visitConstantFieldref(ConstantFieldref obj){
      if (obj.getTag() != Constants.CONSTANT_Fieldref){
        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.getNameAndTypeIndex(), CONST_NameAndType);
    }
    @Override
        public void visitConstantMethodref(ConstantMethodref obj){
      if (obj.getTag() != Constants.CONSTANT_Methodref){
        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.getNameAndTypeIndex(), CONST_NameAndType);
    }
    @Override
        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.getNameAndTypeIndex(), CONST_NameAndType);
    }
    @Override
        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

    while (supidx != 0){
      supidx = jc.getSuperclassNameIndex();
   
      if (supidx == 0){
        if (jc != Repository.lookupClass(Type.OBJECT.getClassName())){
          throw new ClassConstraintException("Superclass of '"+jc.getClassName()+"' missing but not "+Type.OBJECT.getClassName()+" itself!");
        }
      }
      else{
        String supername = jc.getSuperclassName();
        if (! hs.add(supername)){  // If supername already is in the list
          throw new ClassConstraintException("Circular superclass hierarchy detected.");
        }
        Verifier v = VerifierFactory.getVerifier(supername);
        VerificationResult vr = v.doPass1();

        if (vr != VerificationResult.VR_OK){
          throw new ClassConstraintException("Could not load in ancestor class '"+supername+"'.");
        }
        jc = Repository.lookupClass(supername);

        if (jc.isFinal()){
          throw new ClassConstraintException("Ancestor class '"+supername+"' has the FINAL access modifier and must therefore not be subclassed.");
        }
      }
    }

      } catch (ClassNotFoundException e) {
View Full Code Here

        String name_and_sig = (methods[i].getName()+methods[i].getSignature());

        if (hashmap.containsKey(name_and_sig)){
          if ( methods[i].isFinal() ){
            if (!(methods[i].isPrivate())) {
              throw new ClassConstraintException("Method '"+name_and_sig+"' in class '"+hashmap.get(name_and_sig)+"' overrides the final (not-overridable) definition in class '"+jc.getClassName()+"'.");
            }
            else{
              addMessage("Method '"+name_and_sig+"' in class '"+hashmap.get(name_and_sig)+"' overrides the final (not-overridable) definition in class '"+jc.getClassName()+"'. This is okay, as the original definition was private; however this constraint leverage was introduced by JLS 8.4.6 (not vmspec2) and the behaviour of the Sun verifiers.");
            }
          }
View Full Code Here

              offsets.add(offset);
            }
            continue lineNumber_loop;
          }
        }
        throw new ClassConstraintException("Code attribute '"+code+"' has a LineNumberTable attribute '"+code.getLineNumberTable()+"' referring to a code offset ('"+lineNumbers[i].getStartPC()+"') that does not exist.");
      }
    }

    ///////////////////////////
    // LocalVariableTable(s) //
    ///////////////////////////
    /* We cannot use code.getLocalVariableTable() because there could be more
       than only one. This is a bug in BCEL. */
    Attribute[] atts = code.getAttributes();
    for (int a=0; a<atts.length; a++){
      if (atts[a] instanceof LocalVariableTable){
        LocalVariableTable lvt = (LocalVariableTable) atts[a];
        if (lvt != null){
          LocalVariable[] localVariables = lvt.getLocalVariableTable();
          for (int i=0; i<localVariables.length; i++){
            int startpc = localVariables[i].getStartPC();
            int length  = localVariables[i].getLength();
       
            if (!contains(instructionPositions, startpc)){
              throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset ('"+startpc+"') that does not exist.");
            }
            if ( (!contains(instructionPositions, startpc+length)) && (startpc+length != codeLength) ){
              throw new ClassConstraintException("Code attribute '"+code+"' has a LocalVariableTable attribute '"+code.getLocalVariableTable()+"' referring to a code offset start_pc+length ('"+(startpc+length)+"') that does not exist.");
            }
          }
        }
      }
    }
   
    ////////////////////
    // ExceptionTable //
    ////////////////////
    // In BCEL's "classfile" API, the startPC/endPC-notation is
    // inclusive/exclusive as in the Java Virtual Machine Specification.
    // WARNING: This is not true for BCEL's "generic" API.
    CodeException[] exceptionTable = code.getExceptionTable();
    for (int i=0; i<exceptionTable.length; i++){
      int startpc = exceptionTable[i].getStartPC();
      int endpc = exceptionTable[i].getEndPC();
      int handlerpc = exceptionTable[i].getHandlerPC();
      if (startpc >= endpc){
        throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has its start_pc ('"+startpc+"') not smaller than its end_pc ('"+endpc+"').");
      }
      if (!contains(instructionPositions, startpc)){
        throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its start_pc ('"+startpc+"').");
      }
      if ( (!contains(instructionPositions, endpc)) && (endpc != codeLength)){
        throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its end_pc ('"+startpc+"') [that is also not equal to code_length ('"+codeLength+"')].");
      }
      if (!contains(instructionPositions, handlerpc)){
        throw new ClassConstraintException("Code attribute '"+code+"' has an exception_table entry '"+exceptionTable[i]+"' that has a non-existant bytecode offset as its handler_pc ('"+handlerpc+"').");
      }
    }
  }
View Full Code Here

      checkIndex(obj, obj.getStringIndex(), CONST_Utf8);
    }
    @Override
        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

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.