@Override public void report() { // Find the set of properties for which we have both // unsynchronized get and synchronized set methods Set<String> commonProperties = new HashSet<>(getMethods.keySet()); commonProperties.retainAll(setMethods.keySet()); // Report method pairs for (String propName : commonProperties) { MethodAnnotation getMethod = getMethods.get(propName); MethodAnnotation setMethod = setMethods.get(propName); bugReporter.reportBug(new BugInstance(this, "UG_SYNC_SET_UNSYNC_GET", NORMAL_PRIORITY).addClass(prevClassName) .addMethod(getMethod).addMethod(setMethod)); } getMethods.clear(); setMethods.clear(); }
public BugInstance makeWarning(String bugPattern, Object descriptor, int priority, ClassDescriptor cd) { BugInstance bug = new BugInstance(this, bugPattern, priority).addClass(cd); if (descriptor instanceof FieldDescriptor) { bug.addField((FieldDescriptor)descriptor); } else if (descriptor instanceof MethodDescriptor) { bug.addMethod((MethodDescriptor)descriptor); } else if (descriptor instanceof ClassDescriptor) { bug.addClass((ClassDescriptor)descriptor); } if (DEBUG) { System.out.println("Reporting " + bug); } return bug; }
if (fields != null && fields.contains(f)) { warningGiven.add(f); BugInstance bug = new BugInstance(this, "SI_INSTANCE_BEFORE_FINALS_ASSIGNED", NORMAL_PRIORITY).addClassAndMethod(this); if (i.field != null) { bug.addField(i.field).describe(FieldAnnotation.STORED_ROLE); bug.addMethod(i.constructor).describe(MethodAnnotation.METHOD_CONSTRUCTOR); bug.addReferencedField(this).describe(FieldAnnotation.VALUE_OF_ROLE).addSourceLine(this, i.pc); bugReporter.reportBug(bug); break;
int[] oldStartEnd = iterator.next(); if(codeEquals(oldStartEnd, startEnd)) { Item item1 = getStack().getStackItem(0); Item item2 = getStack().getStackItem(1); accumulator.accumulateBug( new BugInstance("CO_COMPARETO_INCORRECT_FLOATING", NORMAL_PRIORITY).addClassAndMethod(this) .addType(item1.getSignature()) .addMethod(item1.getSignature().equals("D")?DOUBLE_DESCRIPTOR:FLOAT_DESCRIPTOR).describe(MethodAnnotation.SHOULD_CALL) .addValueSource(item1, this) .addValueSource(item2, this), this); OpcodeStack.Item top = stack.getStackItem(0); Object o = top.getConstant(); if (o instanceof Integer && ((Integer)o).intValue() == Integer.MIN_VALUE) { accumulator.accumulateBug( new BugInstance(this, "CO_COMPARETO_RESULTS_MIN_VALUE", NORMAL_PRIORITY).addClassAndMethod(this), this);
} else { prio = NORMAL_PRIORITY; Object constantValue = stack.getStackItem(0).getConstant(); if (constantValue instanceof Number) { long value = ((Number) constantValue).longValue(); BugInstance bug = new BugInstance(this, type, prio).addClass(this).addMethod(this).addCalledMethod(this) .addMethod(shouldCall).describe("SHOULD_CALL"); bugAccumulator.accumulateBug(bug, this);
bugReporter.reportBug(new BugInstance(this, "EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC", NORMAL_PRIORITY) .add(childClass).addMethod(equalsMethod.get(childClass)).addMethod(equalsMethod.get(parentClass)) .describe(MethodAnnotation.METHOD_OVERRIDDEN));
pendingBug.addClass(superclassName).describe(role); try { XClass from = Global.getAnalysisCache().getClassAnalysis(XClass.class, pendingBug.addMethod(potentialMatch) .describe(MethodAnnotation.METHOD_DID_YOU_MEAN_TO_OVERRIDE); pendingBug.addMethod(potentialSuperCall).describe(MethodAnnotation.METHOD_DID_YOU_MEAN_TO_OVERRIDE); bugReporter.reportBug(pendingBug); pendingBug = null; potentialSuperCall = null;
priority++; BugInstance warning = new BugInstance(this, "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", priority) .addClassAndMethod(this).addMethod(callSeen).describe(MethodAnnotation.METHOD_CALLED); bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(this, callPC)); } else { pattern = "RV_EXCEPTION_NOT_THROWN"; BugInstance warning = new BugInstance(this, pattern, priority).addClassAndMethod(this).addMethod(callSeen) .describe(MethodAnnotation.METHOD_CALLED); bugAccumulator.accumulateBug(warning, SourceLineAnnotation.fromVisitedInstruction(this, callPC));
@Override public void visitMethodInsn(int opcode, String owner, String invokedName, String invokedDesc, boolean itf) { if (prevPC + 1 == getPC() && prevOpcode == I2D && opcode == INVOKESTATIC && "java/lang/Math".equals(owner) && "ceil".equals(invokedName) && "(D)D".equals(invokedDesc)) { BugInstance bug0 = new BugInstance(TestASM.this, "ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL", NORMAL_PRIORITY); MethodAnnotation methodAnnotation = MethodAnnotation.fromForeignMethod(TestASM.this.name, name, desc, access); bug0.addClass(TestASM.this).addMethod(methodAnnotation); bugReporter.reportBug(bug0); } } };
@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)); } } } }
OpcodeStack.Item left = stack.getStackItem(1); OpcodeStack.Item right = stack.getStackItem(0); if (badUseOfCompareResult(left, right)) { XMethod returnValueOf = left.getReturnValueOf(); assert returnValueOf != null; bugAccumulator.accumulateBug(new BugInstance(this, "RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", NORMAL_PRIORITY) .addClassAndMethod(this).addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addValueSource(right, this), this); } else if (badUseOfCompareResult(right, left)) { XMethod returnValueOf = right.getReturnValueOf(); assert returnValueOf != null; bugAccumulator.accumulateBug(new BugInstance(this, "RV_CHECK_COMPARETO_FOR_SPECIFIC_RETURN_VALUE", NORMAL_PRIORITY) .addClassAndMethod(this).addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addValueSource(left, this), this); OpcodeStack.Item invokedOn = stack.getStackItem(arguments); if (invokedOn.isNewlyAllocated() && (!Const.CONSTRUCTOR_NAME.equals(getMethodName()) || invokedOn.getRegisterNumber() != 0)) { priority++; bugAccumulator.accumulateBug(new BugInstance(this, annotation.getPattern(), priority).addClassAndMethod(this) .addCalledMethod(this), this);
MethodAnnotation ma = MethodAnnotation.fromVisitedMethod(this); bugAccumulator.accumulateBug(mapVariable .annotate(new BugInstance(this, "WMI_WRONG_MAP_ITERATOR", NORMAL_PRIORITY).addClass(this).addMethod(ma)), this); reset();
/** * Add class and method annotations for given class and method. * * @param javaClass * the class * @param method * the method * @return this object */ @Nonnull public BugInstance addClassAndMethod(JavaClass javaClass, Method method) { addClass(javaClass.getClassName()); addMethod(javaClass, method); if (!MemberUtils.isUserGenerated(method)) { foundInAutogeneratedMethod(); } return this; }
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { if (Character.isUpperCase(name.charAt(0))) { BugInstance bug0 = new BugInstance(this, "NM_METHOD_NAMING_CONVENTION", NORMAL_PRIORITY).addClass(this).addMethod( this.name, name, desc, access); bugReporter.reportBug(bug0); } return new AbstractFBMethodVisitor() { int prevOpcode; int prevPC; @Override public void visitInsn(int opcode) { prevOpcode = opcode; prevPC = getPC(); } @Override public void visitMethodInsn(int opcode, String owner, String invokedName, String invokedDesc, boolean itf) { if (prevPC + 1 == getPC() && prevOpcode == I2D && opcode == INVOKESTATIC && "java/lang/Math".equals(owner) && "ceil".equals(invokedName) && "(D)D".equals(invokedDesc)) { BugInstance bug0 = new BugInstance(TestASM.this, "ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL", NORMAL_PRIORITY); MethodAnnotation methodAnnotation = MethodAnnotation.fromForeignMethod(TestASM.this.name, name, desc, access); bug0.addClass(TestASM.this).addMethod(methodAnnotation); bugReporter.reportBug(bug0); } } }; }
return; BugInstance warning = new BugInstance(this, bugType, priority).addClassAndMethod(classContext.getJavaClass(), method) .addMethod(calledMethod).describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, location); warning.addMethod(dangerousCallTarget).describe(MethodAnnotation.METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL); warning.addMethod(dangerousCallTarget).describe(MethodAnnotation.METHOD_DANGEROUS_TARGET); warning.addMethod(safeMethod).describe(MethodAnnotation.METHOD_SAFE_TARGET); bugReporter.reportBug(warning);
if (opcode == Const.PUTFIELD) { XField f = getXFieldOperand(); OpcodeStack.Item item = stack.getStackItem(1); if (item.getRegisterNumber() != 0) { return; return; OpcodeStack.Item item = stack.getStackItem(0); if (item.getRegisterNumber() != 0) { return; BugInstance bug = new BugInstance(this, "UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR", priority).addClassAndMethod( this).addField(f); bug.addMethod(p.method).describe(MethodAnnotation.METHOD_SUPERCLASS_CONSTRUCTOR) .addSourceLine(p.getSourceLineAnnotation()).describe(SourceLineAnnotation.ROLE_CALLED_FROM_SUPERCLASS_AT) .addMethod(upcall).describe(MethodAnnotation.METHOD_CONSTRUCTOR).add(fieldSetAt) .describe(SourceLineAnnotation.ROLE_FIELD_SET_TOO_LATE_AT);
/** * Add a class annotation and a method annotation for the class and method * which the given visitor is currently visiting. * * @param visitor * the BetterVisitor * @return this object */ @Nonnull public BugInstance addClassAndMethod(PreorderVisitor visitor) { addClass(visitor); XMethod m = visitor.getXMethod(); addMethod(visitor); if (!MemberUtils.isUserGenerated(m)) { foundInAutogeneratedMethod(); } return this; }
@Override public void sawOpcode(int seen) { //printOpCode(seen); if(seen == INVOKESPECIAL) { String methodName = getNameConstantOperand(); String className = getClassConstantOperand(); if (methodName.equals("<init>") && className.toLowerCase().endsWith("spelview")) { //Constructor named SpelView() bugReporter.reportBug(new BugInstance(this, "SPEL_INJECTION", Priorities.NORMAL_PRIORITY) // .addClass(this).addMethod(this).addSourceLine(this).addString("SpelView()")); } } } }
bugReporter.reportBug(new BugInstance(this, "TESTING", Priorities.NORMAL_PRIORITY) .addClassAndMethod(classContext.getJavaClass(), method) .addString("Call to method that always throws Exception").addMethod(primaryXMethod) .describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, loc));