/** * Add an annotation about a parameter * * @param index parameter index, starting from 0 * * @param role the role used to describe the parameter */ @Nonnull public BugInstance addParameterAnnotation(int index, String role) { return addInt(index + 1).describe(role); }
@Override public void report() { for (Map.Entry<String, SortedSet<String>> e : map.entrySet()) { Set<String> occursIn = e.getValue(); if (occursIn.size() == 1) { continue; } XField field = definition.get(e.getKey()); if (field == null) { continue; } Integer length = stringSize.get(e.getKey()); int overhead = length * (occursIn.size() - 1); if (overhead < 3 * SIZE_OF_HUGE_CONSTANT) { continue; } String className = field.getClassName(); BugInstance bug = new BugInstance(this, "HSC_HUGE_SHARED_STRING_CONSTANT", overhead > 20 * SIZE_OF_HUGE_CONSTANT ? HIGH_PRIORITY : (overhead > 8 * SIZE_OF_HUGE_CONSTANT ? NORMAL_PRIORITY : LOW_PRIORITY)).addClass(className) .addField(field).addInt(length).addInt(occursIn.size()).describe(IntAnnotation.INT_OCCURRENCES); for (String c : occursIn) { if (!c.equals(className)) { bug.addClass(c); } } bugReporter.reportBug(bug); } }
} else { bugInstance = new BugInstance(this, guardedByThis ? "IS_FIELD_NOT_GUARDED" : "IS2_INCONSISTENT_SYNC", Priorities.NORMAL_PRIORITY).addClass(xfield.getClassName()).addField(xfield).addInt(printFreq) .describe(IntAnnotation.INT_SYNC_PERCENT); bugInstance.addInt(biasedLocked).describe("INT_BIASED_LOCKED"); bugInstance.addInt(biasedUnlocked).describe("INT_BIASED_UNLOCKED");
@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
bugInstance.addInt(state.getObligationSet().getCount(obligation.getId())).describe( IntAnnotation.INT_OBLIGATIONS_REMAINING);
|| c instanceof ConstantLong && ((ConstantLong) c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT)) { BugInstance bug = new BugInstance(this, "TESTING", HIGH_PRIORITY).addClassAndMethod(this) .addString("Did you mean MICROS_PER_DAY").addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE); accumulator.accumulateBug(bug, this); new BugInstance(this, "TESTING", HIGH_PRIORITY).addClassAndMethod(this) .addString("Comparison of getYear does understand that it returns year-1900") .addMethod(returnValueOf).describe(MethodAnnotation.METHOD_CALLED).addInt(year) .describe(IntAnnotation.INT_VALUE), this); if (v <= -129 || v >= 128) { accumulator.accumulateBug(new BugInstance(this, "INT_BAD_COMPARISON_WITH_SIGNED_BYTE", HIGH_PRIORITY) .addClassAndMethod(this).addInt(v).describe(IntAnnotation.INT_VALUE), SourceLineAnnotation.fromVisitedInstruction(this, getPC() + switchOffsets[i])); .addClassAndMethod(this).addInt(v1).describe(IntAnnotation.INT_VALUE).addValueSource(item0, this), this); if (v1 < 0) { accumulator.accumulateBug(new BugInstance(this, "INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE", HIGH_PRIORITY).addClassAndMethod(this).addInt(v1).describe(IntAnnotation.INT_VALUE).addValueSource(item0, this), this); NORMAL_PRIORITY).addClassAndMethod(this).addInt(0).describe(IntAnnotation.INT_VALUE).addValueSource(top, this), this);
warning.addString((String) constantValue).describe(StringAnnotation.STRING_CONSTANT_ROLE); } else if (constantValue instanceof Integer) { warning.addInt((Integer) constantValue).describe(IntAnnotation.INT_VALUE); } else if (constantValue == null) { warning.addString("null").describe(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE);
.addInt(c).describe(IntAnnotation.INT_SHIFT) .addValueSource(stack.getStackItem(2), this) .addValueSource(stack.getStackItem(0), this) valueOfConstantArgumentToShift < 0 ? LOW_PRIORITY : (valueOfConstantArgumentToShift == 32 && "hashCode".equals(getMethodName()) ? NORMAL_PRIORITY : HIGH_PRIORITY)) .addClassAndMethod(this).addInt(valueOfConstantArgumentToShift).describe(IntAnnotation.INT_SHIFT) .addValueSource(stack.getStackItem(1), this), this); int v = (Integer) o; if (v < 0 || v > 11) { bugReporter.reportBug(new BugInstance(this, "DMI_BAD_MONTH", HIGH_PRIORITY).addClassAndMethod(this).addInt(v) .describe(IntAnnotation.INT_VALUE).addCalledMethod(this).addSourceLine(this)); if (v < 0 || v > 11) { bugReporter.reportBug(new BugInstance(this, "DMI_BAD_MONTH", NORMAL_PRIORITY).addClassAndMethod(this) .addInt(v).describe(IntAnnotation.INT_VALUE).addCalledMethod(this).addSourceLine(this));
private BugInstance getRawBug(int placeholders) { return bug.addInt(placeholders); }
/** * Add an annotation about a parameter * * @param index parameter index, starting from 0 * * @param role the role used to describe the parameter */ @Nonnull public BugInstance addParameterAnnotation(int index, String role) { return addInt(index + 1).describe(role); }
private BugInstance createPlaceHolderMismatchBugInstance( int placeholderCount, int parameterCount) { BugInstance bug = new BugInstance(this, "SLF4J_PLACE_HOLDER_MISMATCH", HIGH_PRIORITY) .addSourceLine(this) .addClassAndMethod(this) .addCalledMethod(this) .addInt(parameterCount); if (placeholderCount != -1) { bug.addInt(placeholderCount); } return bug; }
@Override public void report() { for (Map.Entry<String, SortedSet<String>> e : map.entrySet()) { Set<String> occursIn = e.getValue(); if (occursIn.size() == 1) { continue; } XField field = definition.get(e.getKey()); if (field == null) { continue; } Integer length = stringSize.get(e.getKey()); int overhead = length * (occursIn.size() - 1); if (overhead < 3 * SIZE_OF_HUGE_CONSTANT) { continue; } String className = field.getClassName(); BugInstance bug = new BugInstance(this, "HSC_HUGE_SHARED_STRING_CONSTANT", overhead > 20 * SIZE_OF_HUGE_CONSTANT ? HIGH_PRIORITY : (overhead > 8 * SIZE_OF_HUGE_CONSTANT ? NORMAL_PRIORITY : LOW_PRIORITY)).addClass(className) .addField(field).addInt(length).addInt(occursIn.size()).describe(IntAnnotation.INT_OCCURRENCES); for (String c : occursIn) { if (!c.equals(className)) { bug.addClass(c); } } bugReporter.reportBug(bug); } }
.addSourceLine(classContext, this, 0).addInt(branches);
.addSourceLine(classContext, this, 0).addInt(branches);
@Override public void visit(Field field) { ConstantValue value = field.getConstantValue(); if (value == null) { return; } Constant c = getConstantPool().getConstant(value.getConstantValueIndex()); if (testingEnabled && c instanceof ConstantLong && ((ConstantLong)c).getBytes() == MICROS_PER_DAY_OVERFLOWED_AS_INT) { bugReporter.reportBug( new BugInstance(this, "TESTING", HIGH_PRIORITY).addClass(this).addField(this) .addString("Did you mean MICROS_PER_DAY") .addInt(MICROS_PER_DAY_OVERFLOWED_AS_INT) .describe(IntAnnotation.INT_VALUE)); } } @Override
bugInstance.addInt(state.getObligationSet().getCount(obligation.getId())).describe( IntAnnotation.INT_OBLIGATIONS_REMAINING);
warning.addString((String) constantValue).describe(StringAnnotation.STRING_CONSTANT_ROLE); } else if (constantValue instanceof Integer) { warning.addInt((Integer) constantValue).describe(IntAnnotation.INT_VALUE); } else if (constantValue == null) { warning.addString("null").describe(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE);
.addClassAndMethod(this).addCalledMethod(this).addString(e.formatSpecifier) .describe(StringAnnotation.FORMAT_SPECIFIER_ROLE).addString(formatString) .describe(StringAnnotation.FORMAT_STRING_ROLE).addInt(e.pos + 1) .describe(IntAnnotation.INT_EXPECTED_ARGUMENTS).addInt(arguments.length) .describe(IntAnnotation.INT_ACTUAL_ARGUMENTS).addSourceLine(this)); .addString(formatString).describe(StringAnnotation.FORMAT_STRING_ROLE).addInt(e.used) .describe(IntAnnotation.INT_EXPECTED_ARGUMENTS).addInt(e.provided) .describe(IntAnnotation.INT_ACTUAL_ARGUMENTS).addSourceLine(this)); } catch (FormatterNumberFormatException e) {