/** * If feature is enabled, suppress warnings where there is at least one live * store on the line where the warning would be reported. * * @param accumulator * BugAccumulator containing warnings for method * @param liveStoreSourceLineSet * bitset of lines where at least one live store was seen */ private void suppressWarningsIfOneLiveStoreOnLine(BugAccumulator accumulator, BitSet liveStoreSourceLineSet) { if (!SUPPRESS_IF_AT_LEAST_ONE_LIVE_STORE_ON_LINE) { return; } // Eliminate any accumulated warnings for instructions // that (due to inlining) *can* be live stores. entryLoop: for (Iterator<? extends BugInstance> i = accumulator.uniqueBugs().iterator(); i.hasNext();) { for (SourceLineAnnotation annotation : accumulator.locations(i.next())) { if (liveStoreSourceLineSet.get(annotation.getStartLine())) { // This instruction can be a live store; don't report // it as a warning. i.remove(); continue entryLoop; } } } }
public void reportBug(BugInstance bug, Data d) { bug.setPriority(d.priority); bug.addSourceLine(d.primarySource); HashSet<Integer> lines = new HashSet<>(); lines.add(d.primarySource.getStartLine()); d.allSource.remove(d.primarySource); for (SourceLineAnnotation source : d.allSource) { if (lines.add(source.getStartLine())) { bug.addSourceLine(source); bug.describe(SourceLineAnnotation.ROLE_ANOTHER_INSTANCE); } /* else if (false && SystemProperties.ASSERTIONS_ENABLED) { AnalysisContext.logError("Skipping duplicated source warning for " + bug.getInstanceHash() + " " + bug.getMessage()); }*/ } reporter.reportBug(bug); }
@Override public BugInstance findBug(String instanceHash, String bugType, int lineNumber) { for (BugInstance bug : bugSet) { if (bug.getInstanceHash().equals(instanceHash) && bug.getBugPattern().getType().equals(bugType) && bug.getPrimarySourceLineAnnotation().getStartLine() == lineNumber) { return bug; } } return null; }
@Override public void visitInstructionHandle(InstructionHandle handle) { boolean isCreation = (dataflow.getAnalysis().getActionCache().addsObligation(curBlock, handle, obligation)); if (!sawFirstCreation && !isCreation) { return; } SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(methodDescriptor, new Location( handle, curBlock)); sourceLine.setDescription(isCreation ? SourceLineAnnotation.ROLE_OBLIGATION_CREATED : SourceLineAnnotation.ROLE_PATH_CONTINUES); boolean isInteresting = (sourceLine.getStartLine() > 0) && (lastSourceLine == null || isCreation || sourceLine.getStartLine() != lastSourceLine.getStartLine()); if (REPORT_PATH_DEBUG) { System.out.println(" " + handle.getPosition() + " --> " + sourceLine + (isInteresting ? " **" : "")); } if (isInteresting) { bugInstance.add(sourceLine); lastSourceLine = sourceLine; if (isCreation) { sawFirstCreation = true; } } }
hashes.put(key, buf); buf.append(bug.getInstanceKey()).append("-").append(source.getStartLine()).append(".") .append(source.getStartBytecode()).append(" "); Integer count = counts.get(key);
private void annotateAndReport(BugInstance bug, OpcodeStack.Item item) { assert item.isServletParameterTainted(); String s = item.getHttpParameterName(); int pc = item.getInjectionPC(); if (s != null && xmlSafe.matcher(s).matches()) { bug.addString(s).describe(StringAnnotation.PARAMETER_NAME_ROLE); } SourceLineAnnotation thisLine = SourceLineAnnotation.fromVisitedInstruction(this); if (pc >= 0) { SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(this, pc); if (thisLine.getStartLine() != source.getStartLine()) { bug.add(source).describe(SourceLineAnnotation.ROLE_GENERATED_AT); } } bug.addOptionalLocalVariable(this, item); accumulator.accumulateBug(bug, this); }
lineStart = line.getStartLine(); lineEnd = line.getEndLine(); SourceFinder sourceFinder = AnalysisContext.currentAnalysisContext().getSourceFinder();
return false; criteriaMatches &= srcAnn.getStartLine() <= lineNumber && lineNumber <= srcAnn.getEndLine(); return false; criteriaMatches &= srcAnn.getStartLine()-1 <= lineNumberApprox && lineNumberApprox <= srcAnn.getEndLine()+1; if(srcAnn.getStartLine()-1 <= potentialMatch && potentialMatch <= srcAnn.getEndLine()+1) { found = true;
SourceFile sourceFile = sourceFinder.findSourceFile(srcLine.getPackageName(), srcLine.getSourceFile()); int startLine = srcLine.getStartLine(); int numLines = srcLine.getEndLine() - startLine - 1; if (numLines <= 0) {
try { SourceFile sourceFile = sourceFinder.findSourceFile(srcLine.getPackageName(), srcLine.getSourceFile()); int startLine = srcLine.getStartLine();
if (firstSourceLine.getStartLine() == -1 || firstSourceLine.getStartLine() != secondSourceLine.getEndLine()) { priority++;
int n = getStartLine(); // start/end are now optional (were too many
static SourceLineAnnotation obfuscate(SourceLineAnnotation m) { SourceLineAnnotation result = new SourceLineAnnotation(hashClass(m.getClassName()), hashFilename(m.getSourceFile()), m.getStartLine(), m.getEndLine(), m.getStartBytecode(), m.getEndBytecode()); result.setDescription(m.getDescription()); return result; }
continue; int startLine = sourceLineAnnotation.getStartLine(); if (startLine == -1) { knownNullLocations.add(sourceLineAnnotation); assignedNull); if (sourceLineAnnotation != null) { int startLine = sourceLineAnnotation.getStartLine(); if (startLine > 0 && !knownNull.get(startLine)) { bugInstance.add(sourceLineAnnotation).describe("SOURCE_LINE_NULL_VALUE");
private void foundSwitchNoDefault(SourceLineAnnotation s) { LineNumberTable table = getCode().getLineNumberTable(); if (table != null) { int startLine = s.getStartLine(); int prev = Integer.MIN_VALUE; for (LineNumber ln : table.getLineNumberTable()) { int thisLineNumber = ln.getLineNumber(); if (thisLineNumber < startLine && thisLineNumber > prev && ln.getStartPC() < s.getStartBytecode()) { prev = thisLineNumber; } } int diff = startLine - prev; if (diff > 5) { return; } bugAccumulator.accumulateBug(new BugInstance(this, "SF_SWITCH_NO_DEFAULT", NORMAL_PRIORITY).addClassAndMethod(this), s); } }
boolean possibleClone = source.getStartLine() > 0 && linesMentionedMultipleTimes.get(source.getStartLine()); LineNumberTable lineNumberTable = getCode().getLineNumberTable(); int linesDifference = 0;
int loopBottomLine = loopBottom.getStartLine(); SourceLineAnnotation loopTop = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, bb.to); int loopTopLine = loopTop.getStartLine(); BugInstance bug = new BugInstance(this, "IL_INFINITE_LOOP", HIGH_PRIORITY).addClassAndMethod(this) .addSourceLine(this, fcb.from).addSourceLine(loopBottom)
public void toElement(BugInstance bugInstance) { String className = bugInstance.getPrimaryClass().getClassName(); Element element = (Element) root.selectSingleNode(FILE_ELEMENT_NAME + "[@classname='" + className + "']"); if (element == null) { element = root.addElement(FILE_ELEMENT_NAME); element.addAttribute("classname", className); } element = element.addElement(ELEMENT_NAME); element.addAttribute("type", bugInstance.getType()); switch (bugInstance.getPriority()) { case Priorities.EXP_PRIORITY: element.addAttribute("priority", "Experimental"); break; case Priorities.LOW_PRIORITY: element.addAttribute("priority", "Low"); break; case Priorities.NORMAL_PRIORITY: element.addAttribute("priority", "Normal"); break; case Priorities.HIGH_PRIORITY: element.addAttribute("priority", "High"); break; default: assert false; } element.addAttribute("message", xmlEscape(bugInstance.getMessage())); SourceLineAnnotation line = bugInstance.getPrimarySourceLineAnnotation(); element.addAttribute("line", Integer.toString(line.getStartLine())); }
int startLine = sourceLineAnnotation.getStartLine(); if (startLine > 0 && lineMentionedMultipleTimes.get(startLine) && linesWithLoadsOfNotDefinitelyNullValues.get(startLine)) {
int line = sourceLine.getStartLine(); BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method); if (line > 0 && occursMultipleTimes.get(line)) {