@Override public void visit(Code obj) { sawSuperFinalize = false; super.visit(obj); bugAccumulator.reportAccumulatedBugs(); if (!getMethodName().equals("finalize") || !getMethodSig().equals("()V")) return; String overridesFinalizeIn = Lookup.findSuperImplementor(getDottedClassName(), "finalize", "()V", bugReporter); boolean superHasNoFinalizer = overridesFinalizeIn.equals("java.lang.Object"); // System.out.println("superclass: " + superclassName); if (obj.getCode().length == 1) { if (superHasNoFinalizer) { if (!getMethod().isFinal()) bugReporter.reportBug( new BugInstance(this, "FI_EMPTY", NORMAL_PRIORITY).addClassAndMethod(this)); } else bugReporter.reportBug( new BugInstance(this, "FI_NULLIFY_SUPER", NORMAL_PRIORITY) .addClassAndMethod(this) .addClass(overridesFinalizeIn)); } else if (obj.getCode().length == 5 && sawSuperFinalize) bugReporter.reportBug( new BugInstance(this, "FI_USELESS", NORMAL_PRIORITY).addClassAndMethod(this)); else if (!sawSuperFinalize && !superHasNoFinalizer) bugReporter.reportBug( new BugInstance(this, "FI_MISSING_SUPER_CALL", NORMAL_PRIORITY) .addClassAndMethod(this) .addClass(overridesFinalizeIn)); }
/** Loads the code of the method. */ protected Instruction[] loadCode(Method m) { Code c = m.getCode(); if (c == null) { return null; } InstructionList il = new InstructionList(c.getCode()); InstructionHandle[] hs = il.getInstructionHandles(); int length = hs.length; Instruction[] is = new Instruction[length]; for (int i = 0; i < length; i++) { is[i] = insnFactory.createAndInitialize(this, hs[i], i, m.getConstantPool()); if (c.getLineNumberTable() != null) { // annoying bug when BCEL don't seem to find linenumber - pos match // also sometimes linenumber tables are not available is[i].setContext( ci.getName(), name, c.getLineNumberTable().getSourceLine(is[i].getPosition()), is[i].getPosition()); } } return is; }
@Override public void visit(Code obj) { if (!directChildOfTestCase && (getMethodName().equals("setUp") || getMethodName().equals("tearDown")) && !getMethod().isPrivate() && getMethodSig().equals("()V")) { sawSuperCall = false; super.visit(obj); if (sawSuperCall) { return; } JavaClass we = Lookup.findSuperImplementor(getThisClass(), getMethodName(), "()V", bugReporter); if (we != null && !we.getClassName().equals("junit.framework.TestCase")) { // OK, got a bug int offset = 0; if (getMethodName().equals("tearDown")) { offset = obj.getCode().length - 1; } Method superMethod = Lookup.findImplementation(we, getMethodName(), "()V"); Code superCode = superMethod.getCode(); if (superCode != null && superCode.getCode().length > 3) { bugReporter.reportBug( new BugInstance( this, getMethodName().equals("setUp") ? "IJU_SETUP_NO_SUPER" : "IJU_TEARDOWN_NO_SUPER", NORMAL_PRIORITY) .addClassAndMethod(this) .addMethod(we, superMethod) .describe(MethodAnnotation.METHOD_OVERRIDDEN) .addSourceLine(this, offset)); } } } }