当前位置: 首页>>代码示例>>Java>>正文


Java VerificationResult.VR_OK属性代码示例

本文整理汇总了Java中org.apache.bcel.verifier.VerificationResult.VR_OK属性的典型用法代码示例。如果您正苦于以下问题:Java VerificationResult.VR_OK属性的具体用法?Java VerificationResult.VR_OK怎么用?Java VerificationResult.VR_OK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.bcel.verifier.VerificationResult的用法示例。


在下文中一共展示了VerificationResult.VR_OK属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocalVariablesInfo

/**
 * Returns a LocalVariablesInfo object containing information
 * about the usage of the local variables in the Code attribute
 * of the said method or <B>null</B> if the class file this
 * Pass2Verifier operates on could not be pass-2-verified correctly.
 * The method number method_nr is the method you get using
 * <B>Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];</B>.
 * You should not add own information. Leave that to JustIce.
 */
public LocalVariablesInfo getLocalVariablesInfo(int method_nr){
	if (this.verify() != VerificationResult.VR_OK) {
           return null; // It's cached, don't worry.
       }
	if (method_nr < 0 || method_nr >= localVariablesInfos.length){
		throw new AssertionViolatedException("Method number out of range.");
	}
	return localVariablesInfos[method_nr];
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:18,代码来源:Pass2Verifier.java

示例2: every_class_has_an_accessible_superclass

/**
 * Ensures that every class has a super class and that
 * <B>final</B> classes are not subclassed.
 * This means, the class this Pass2Verifier operates
 * on has proper super classes (transitively) up to
 * java.lang.Object.
 * The reason for really loading (and Pass1-verifying)
 * all of those classes here is that we need them in
 * Pass2 anyway to verify no final methods are overridden
 * (that could be declared anywhere in the ancestor hierarchy).
 *
 * @throws ClassConstraintException otherwise.
 */
private void every_class_has_an_accessible_superclass(){
    try {
	Set hs = new HashSet(); // save class names to detect circular inheritance
	JavaClass jc = Repository.lookupClass(myOwner.getClassName());
	int supidx = -1;

	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) {
	// FIXME: this might not be the best way to handle missing classes.
	throw new AssertionViolatedException("Missing class: " + e.toString());
    }
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:51,代码来源:Pass2Verifier.java

示例3: every_class_has_an_accessible_superclass

/**
 * Ensures that every class has a super class and that
 * <B>final</B> classes are not subclassed.
 * This means, the class this Pass2Verifier operates
 * on has proper super classes (transitively) up to
 * java.lang.Object.
 * The reason for really loading (and Pass1-verifying)
 * all of those classes here is that we need them in
 * Pass2 anyway to verify no final methods are overridden
 * (that could be declared anywhere in the ancestor hierarchy).
 *
 * @throws ClassConstraintException otherwise.
 */
private void every_class_has_an_accessible_superclass() {
    HashSet<String> hs = new HashSet<String>(); // save class names to detect circular inheritance
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());
    int supidx = -1;

    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.");
            }
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:44,代码来源:Pass2Verifier.java

示例4: visitExceptionTable

public void visitExceptionTable(ExceptionTable obj) {//vmspec2 4.7.4
    // incorrectly named, it's the Exceptions attribute (vmspec2 4.7.4)
    checkIndex(obj, obj.getNameIndex(), CONST_Utf8);

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

    int[] exc_indices = obj.getExceptionIndexTable();

    for (int exc_indice : exc_indices) {
        checkIndex(obj, exc_indice, CONST_Class);

        ConstantClass cc = (ConstantClass) (cp.getConstant(exc_indice));
        checkIndex(cc, cc.getNameIndex(), CONST_Utf8); // cannot be sure this ConstantClass has already been visited (checked)!
        String cname = ((ConstantUtf8) cp.getConstant(cc.getNameIndex())).getBytes().replace('/', '.'); //convert internal notation on-the-fly to external notation

        Verifier v = VerifierFactory.getVerifier(cname);
        VerificationResult vr = v.doPass1();

        if (vr != VerificationResult.VR_OK) {
            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();
                if (vr != VerificationResult.VR_OK) {
                    throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname + "' as an Exception but '" + e.getSuperclassName() + "' in the ancestor hierachy does not pass verification pass 1: " + vr);
                } else {
                    e = Repository.lookupClass(e.getSuperclassName());
                }
            }
            if (e != t)
                throw new ClassConstraintException("Exceptions attribute '" + tostring(obj) + "' references '" + cname + "' as an Exception but it is not a subclass of '" + t.getClassName() + "'.");
        }
    }
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:45,代码来源:Pass2Verifier.java

示例5: do_verify

/**
 * Pass 3b implements the data flow analysis as described in the Java Virtual
 * Machine Specification, Second Edition.
 * Later versions will use LocalVariablesInfo objects to verify if the
 * verifier-inferred types and the class file's debug information (LocalVariables
 * attributes) match [TODO].
 *
 * @see org.apache.bcel.verifier.statics.LocalVariablesInfo
 * @see org.apache.bcel.verifier.statics.Pass2Verifier#getLocalVariablesInfo(int)
 */
public VerificationResult do_verify() {
    if (!myOwner.doPass3a(method_no).equals(VerificationResult.VR_OK)) {
        return VerificationResult.VR_NOTYET;
    }

    // Pass 3a ran before, so it's safe to assume the JavaClass object is
    // in the BCEL repository.
    JavaClass jc = Repository.lookupClass(myOwner.getClassName());

    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;
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:79,代码来源:Pass3bVerifier.java

示例6: getLocalVariablesInfo

/**
 * Returns a LocalVariablesInfo object containing information
 * about the usage of the local variables in the Code attribute
 * of the said method or <B>null</B> if the class file this
 * Pass2Verifier operates on could not be pass-2-verified correctly.
 * The method number method_nr is the method you get using
 * <B>Repository.lookupClass(myOwner.getClassname()).getMethods()[method_nr];</B>.
 * You should not add own information. Leave that to JustIce.
 * @param method_nr
 */
public LocalVariablesInfo getLocalVariablesInfo(int method_nr) {
    if (this.verify() != VerificationResult.VR_OK) return null; // It's cached, don't worry.
    if (method_nr < 0 || method_nr >= localVariablesInfos.length) {
        throw new AssertionViolatedException("Method number out of range.");
    }
    return localVariablesInfos[method_nr];
}
 
开发者ID:miuirussia,项目名称:KJBE,代码行数:17,代码来源:Pass2Verifier.java


注:本文中的org.apache.bcel.verifier.VerificationResult.VR_OK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。