/** * Does the given instruction refer to a likely assertion method? * * @param ins * the instruction * @return true if the instruction likely refers to an assertion, false if * not */ public boolean isAssertionInstruction(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof InvokeInstruction) { return isAssertionCall((InvokeInstruction) ins); } if (ins instanceof GETSTATIC) { GETSTATIC getStatic = (GETSTATIC) ins; String className = getStatic.getClassName(cpg); String fieldName = getStatic.getFieldName(cpg); if ("java.util.logging.Level".equals(className) && "SEVERE".equals(fieldName)) { return true; } if ("org.apache.log4j.Level".equals(className) && ("ERROR".equals(fieldName) || "FATAL".equals(fieldName))) { return true; } return false; } return false; }
if(next instanceof IFNE) { GETSTATIC getStatic = (GETSTATIC)ih.getInstruction(); if ("$assertionsDisabled".equals(getStatic.getFieldName(methodGen.getConstantPool())) && "Z".equals(getStatic.getSignature(methodGen.getConstantPool()))) { int end = ((IFNE)next).getTarget().getPosition();
GETSTATIC getStatic = (GETSTATIC) prevInstruction; if ("$assertionsDisabled".equals(getStatic.getFieldName(methodGen.getConstantPool())) && "Z".equals(getStatic.getSignature(methodGen.getConstantPool()))) { edgesToRemove.add(e);
GETSTATIC getStatic = (GETSTATIC) prevIns; ConstantPoolGen cpg = methodGen.getConstantPool(); foundDeadClassInitialization = getStatic.getFieldName(cpg).startsWith("class$") && "Ljava/lang/Class;".equals(getStatic.getSignature(cpg)); for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) {
/** * Does the given instruction refer to a likely assertion method? * * @param ins * the instruction * @return true if the instruction likely refers to an assertion, false if * not */ public boolean isAssertionInstruction(Instruction ins, ConstantPoolGen cpg) { if (ins instanceof InvokeInstruction) { return isAssertionCall((InvokeInstruction) ins); } if (ins instanceof GETSTATIC) { GETSTATIC getStatic = (GETSTATIC) ins; String className = getStatic.getClassName(cpg); String fieldName = getStatic.getFieldName(cpg); if ("java.util.logging.Level".equals(className) && "SEVERE".equals(fieldName)) { return true; } if ("org.apache.log4j.Level".equals(className) && ("ERROR".equals(fieldName) || "FATAL".equals(fieldName))) { return true; } return false; } return false; }
/** 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; } } if (f == null){ throw new AssertionViolatedException("Field not found?!?"); } if (! (f.isStatic())){ constraintViolated(o, "Referenced field '"+f+"' is not static which it should be."); } }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override public void visitGETSTATIC(final GETSTATIC o) { try { final String field_name = o.getFieldName(cpg); final JavaClass jc = Repository.lookupClass(getObjectType(o).getClassName()); final Field[] fields = jc.getFields(); Field f = null; for (final Field field : fields) { if (field.getName().equals(field_name)) { f = field; break; } } if (f == null) { throw new AssertionViolatedException("Field '" + field_name + "' not found in " + jc.getClassName()); } if (! (f.isStatic())) { constraintViolated(o, "Referenced field '"+f+"' is not static which it should be."); } } catch (final ClassNotFoundException e) { // FIXME: maybe not the best way to handle this throw new AssertionViolatedException("Missing class: " + e, e); } }
org.apache.bcel.generic.GETSTATIC getstatic = (org.apache.bcel.generic.GETSTATIC) prev1.getInstruction(); if (getstatic.getClassType(cpg).getClassName().equals("java.lang.Boolean") && getstatic.getFieldName(cpg).equals("FALSE")) { return;
if(next instanceof IFNE) { GETSTATIC getStatic = (GETSTATIC)ih.getInstruction(); if ("$assertionsDisabled".equals(getStatic.getFieldName(methodGen.getConstantPool())) && "Z".equals(getStatic.getSignature(methodGen.getConstantPool()))) { int end = ((IFNE)next).getTarget().getPosition();
org.apache.bcel.generic.GETSTATIC getstatic = (org.apache.bcel.generic.GETSTATIC) prev1.getInstruction(); if (getstatic.getClassType(cpg).getClassName().equals("java.lang.Boolean") && getstatic.getFieldName(cpg).equals("FALSE")) { return;
GETSTATIC gstatCtrlField = (GETSTATIC) match[0].getInstruction(); controlClass = gstatCtrlField.getName(cg.getConstantPool()); String fieldName = gstatCtrlField.getFieldName(cg.getConstantPool()); ClassGen ctrlClazz = cgs.get(controlClass); controlField = ctrlClazz.containsField(fieldName); GETSTATIC gstatCtrlField = (GETSTATIC) iStoreHandle.getPrev().getInstruction(); String className = gstatCtrlField.getName(cg.getConstantPool()); String fieldName = gstatCtrlField.getFieldName(cg.getConstantPool()); ctrlClazz = cgs.get(className); flowObstructor = ctrlClazz.containsField(fieldName);
GETSTATIC gstat = (GETSTATIC) ih.getInstruction(); return flowObstructors.contains(cgs.get(gstat.getName(cpg)) .containsField(gstat.getFieldName(cpg))); } else { ILOAD iLoad = (ILOAD) ih.getInstruction(); .containsField(gstat.getFieldName(cpg))); Field fz = cp.containsField(gstat.getFieldName(cpg)); return cp != null && fz != null && controlField != null && controlField.equals(fz);
GETSTATIC getStatic = (GETSTATIC) prevInstruction; if ("$assertionsDisabled".equals(getStatic.getFieldName(methodGen.getConstantPool())) && "Z".equals(getStatic.getSignature(methodGen.getConstantPool()))) { edgesToRemove.add(e);
GETSTATIC getStatic = (GETSTATIC) prevIns; ConstantPoolGen cpg = methodGen.getConstantPool(); foundDeadClassInitialization = getStatic.getFieldName(cpg).startsWith("class$") && "Ljava/lang/Class;".equals(getStatic.getSignature(cpg)); for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) {