Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.JavaClass


  public JavaClass loadClass( String className )
    throws ClassNotFoundException
  {
    String classFile = className.replace('.', '/');

    JavaClass RC = findClass( className );
    if (RC != null) { return RC; }

    try {
      InputStream is =
  loader.getResourceAsStream( classFile + ".class" );
View Full Code Here


            throw new ClassConstraintException("Code attribute '"+tostring(obj)+"' (method '"+m+"') has an exception_table entry '"+tostring(exc_table[i])+"' that references '"+cname+"' as an Exception but it does not pass verification pass 1: "+vr);
          }
          else{
            // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
            // the ancestor hierarchy.
            JavaClass e = Repository.lookupClass(cname);
            JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
            JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
            while (e != o){
              if (e == t) break; // It's a subclass of Throwable, OKAY, leave.

              v = VerifierFactory.getVerifier(e.getSuperclassName());
              vr = v.doPass1();
View Full Code Here

          throw new ClassConstraintException("Exceptions attribute '"+tostring(obj)+"' references '"+cname+"' as an Exception but it does not pass verification pass 1: "+vr);
        }
        else{
          // We cannot safely trust any other "instanceof" mechanism. We need to transitively verify
          // the ancestor hierarchy.
          JavaClass e = Repository.lookupClass(cname);
          JavaClass t = Repository.lookupClass(Type.THROWABLE.getClassName());
          JavaClass o = Repository.lookupClass(Type.OBJECT.getClassName());
          while (e != o){
            if (e == t) break; // It's a subclass of Throwable, OKAY, leave.

            v = VerifierFactory.getVerifier(e.getSuperclassName());
            vr = v.doPass1();
View Full Code Here

  public static void main(String argv[])
  {
    String[]    file_name = new String[argv.length];
    int         files=0;
    ClassParser parser=null;
    JavaClass   java_class=null;
    String      zip_file = null;
    char        sep = System.getProperty("file.separator").toCharArray()[0];
    String      dir = "." + sep; // Where to store HTML files
 
    try {
View Full Code Here

        constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'.");
      }
     
      String field_name = o.getFieldName(cpg);
      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          f = fields[i];
          break;
        }
      }
      if (f == null){
        /* TODO: also look up if the field is inherited! */
        constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
      }
      else{
        /* TODO: Check if assignment compatibility is sufficient.
           What does Sun do? */
        Type f_type = Type.getType(f.getSignature());
View Full Code Here

    }

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitPUTSTATIC(PUTSTATIC o){
      String field_name = o.getFieldName(cpg);
      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          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.");
      }
    }
View Full Code Here

    }

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitGETSTATIC(GETSTATIC o){
      String field_name = o.getFieldName(cpg);
      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          f = fields[i];
          break;
View Full Code Here

      // INVOKEINTERFACE is a LoadClass; the Class where the referenced method is declared in,
      // is therefore resolved/verified.
      // INVOKEINTERFACE is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verfier does allow the method to be declared in some superinterface, which the Java Virtual Machine Specification, Second Edition does not.");
      }
      if (jc.isClass()){
        constraintViolated(o, "Referenced class '"+jc.getClassName()+"' is a class, but not an interface as expected.");
      }
    }
View Full Code Here

      // INVOKESPECIAL is a LoadClass; the Class where the referenced method is declared in,
      // is therefore resolved/verified.
      // INVOKESPECIAL is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verfier does allow the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
      }
     
      JavaClass current = Repository.lookupClass(myOwner.getClassName());
      if (current.isSuper()){
     
        if ((Repository.instanceOf( current, jc )) && (!current.equals(jc))){
         
          if (! (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME) )){
            // Special lookup procedure for ACC_SUPER classes.
           
            int supidx = -1;
           
            Method meth = null;
            while (supidx != 0){
              supidx = current.getSuperclassNameIndex();
              current = Repository.lookupClass(current.getSuperclassName());
             
              Method[] meths = current.getMethods();
              for (int i=0; i<meths.length; i++){
                if  ( (meths[i].getName().equals(o.getMethodName(cpg))) &&
                     (Type.getReturnType(meths[i].getSignature()).equals(o.getReturnType(cpg))) &&
                     (objarrayequals(Type.getArgumentTypes(meths[i].getSignature()), o.getArgumentTypes(cpg))) ){
                  meth = meths[i];
View Full Code Here

      // INVOKESTATIC is a LoadClass; the Class where the referenced method is declared in,
      // is therefore resolved/verified.
      // INVOKESTATIC is an InvokeInstruction, the argument and return types are resolved/verified,
      // too. So are the allowed method names.
      String classname = o.getClassName(cpg);
      JavaClass jc = Repository.lookupClass(classname);
      Method[] ms = jc.getMethods();
      Method m = null;
      for (int i=0; i<ms.length; i++){
        if ( (ms[i].getName().equals(o.getMethodName(cpg))) &&
             (Type.getReturnType(ms[i].getSignature()).equals(o.getReturnType(cpg))) &&
             (objarrayequals(Type.getArgumentTypes(ms[i].getSignature()), o.getArgumentTypes(cpg))) ){
          m = ms[i];
          break;
        }
      }
      if (m == null){
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' with expected signature not found in class '"+jc.getClassName()+"'. The native verifier possibly allows the method to be declared in some superclass or implemented interface, which the Java Virtual Machine Specification, Second Edition does not.");
      }
     
      if (! (m.isStatic())){ // implies it's not abstract, verified in pass 2.
        constraintViolated(o, "Referenced method '"+o.getMethodName(cpg)+"' has ACC_STATIC unset.");
      }
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.JavaClass

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.