private static int getLineNumber(Method method, InstructionHandle handle) { LineNumberTable table = method.getCode().getLineNumberTable(); if (table == null) { return -1; } return table.getSourceLine(handle.getPosition()); } }
int startLine = lineNumberTable.getSourceLine(startPC); int endLine = lineNumberTable.getSourceLine(endPC); return new SourceLineAnnotation(className, sourceFile, startLine, endLine, startPC, endPC);
private boolean uniqueLocations(Collection<Location> derefLocationSet) { boolean uniqueDereferenceLocations = false; LineNumberTable table = method.getLineNumberTable(); if (table == null) { uniqueDereferenceLocations = true; } else { BitSet linesMentionedMultipleTimes = classContext.linesMentionedMultipleTimes(method); for (Location loc : derefLocationSet) { int lineNumber = table.getSourceLine(loc.getHandle().getPosition()); if (!linesMentionedMultipleTimes.get(lineNumber)) { uniqueDereferenceLocations = true; } } } return uniqueDereferenceLocations; }
/** * Factory method for creating a source line annotation describing the * source line numbers for a range of instructions in the method being * visited by the given visitor. * * @param visitor * a BetterVisitor which is visiting the method * @param startPC * the bytecode offset of the start instruction in the range * @param endPC * the bytecode offset of the end instruction in the range * @return the SourceLineAnnotation, or null if we do not have line number * information for the instruction */ public static SourceLineAnnotation fromVisitedInstructionRange(BytecodeScanningDetector visitor, int startPC, int endPC) { LineNumberTable lineNumberTable = getLineNumberTable(visitor); String className = visitor.getDottedClassName(); String sourceFile = visitor.getSourceFile(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, startPC, endPC); } int startLine = lineNumberTable.getSourceLine(startPC); int endLine = lineNumberTable.getSourceLine(endPC); return new SourceLineAnnotation(className, sourceFile, startLine, endLine, startPC, endPC); }
boolean callToAssertionMethod(Location loc) { InstructionHandle h = loc.getHandle(); int firstPos = h.getPosition(); LineNumberTable ln = method.getLineNumberTable(); int firstLine = ln == null ? -1 : ln.getSourceLine(firstPos); while (h != null) { int pos = h.getPosition(); if (ln == null) { if (pos > firstPos + 15) { break; } } else { int line = ln.getSourceLine(pos); if (line != firstLine) { break; } } Instruction i = h.getInstruction(); if (i instanceof InvokeInstruction) { InvokeInstruction ii = (InvokeInstruction) i; String name = ii.getMethodName(classContext.getConstantPoolGen()); if (name.startsWith("check") || name.startsWith("assert")) { return true; } } h = h.getNext(); } return false; }
@Override public void sawOpcode(int seen) { if (ifInstructionSet.get(seen)) { if (getBranchTarget() == getBranchFallThrough()) { int priority = NORMAL_PRIORITY; LineNumberTable lineNumbers = getCode().getLineNumberTable(); if (lineNumbers != null) { int branchLineNumber = lineNumbers.getSourceLine(getPC()); int targetLineNumber = lineNumbers.getSourceLine(getBranchFallThrough()); int nextLine = getNextSourceLine(lineNumbers, branchLineNumber); if (branchLineNumber + 1 == targetLineNumber || branchLineNumber == targetLineNumber && nextLine == branchLineNumber + 1) { priority = HIGH_PRIORITY; } else if (branchLineNumber + 2 < Math.max(targetLineNumber, nextLine)) { priority = LOW_PRIORITY; } } else { priority = LOW_PRIORITY; } bugAccumulator.accumulateBug(new BugInstance(this, priority == HIGH_PRIORITY ? "UCF_USELESS_CONTROL_FLOW_NEXT_LINE" : "UCF_USELESS_CONTROL_FLOW", priority) .addClassAndMethod(this), this); } } }
/** * Factory method for creating a source line annotation describing the * source line number for a visited instruction. * * @param classContext * the ClassContext * @param methodGen * the MethodGen object representing the method * @param handle * the InstructionHandle containing the visited instruction * @return the SourceLineAnnotation, or null if we do not have line number * information for the instruction */ @Nonnull public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, MethodGen methodGen, String sourceFile, @Nonnull InstructionHandle handle) { LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); int bytecodeOffset = handle.getPosition(); if (table == null) { return createUnknown(className, sourceFile, bytecodeOffset, bytecodeOffset); } int lineNumber = table.getSourceLine(handle.getPosition()); return new SourceLineAnnotation(className, sourceFile, lineNumber, lineNumber, bytecodeOffset, bytecodeOffset); }
sourceLine = table.getSourceLine(bytecodeOffset); } catch (ArrayIndexOutOfBoundsException e) { if (LINE_NUMBER_BUG) {
private boolean uniqueLocations(Collection<Location> derefLocationSet) { boolean uniqueDereferenceLocations = false; CodeException[] exceptionTable = method.getCode().getExceptionTable(); if (exceptionTable == null) { return true; } checkForCatchAll: { for (CodeException e : exceptionTable) { if (e.getCatchType() == 0) { break checkForCatchAll; } } return true; } LineNumberTable table = method.getLineNumberTable(); if (table == null) { uniqueDereferenceLocations = true; } else { BitSet linesMentionedMultipleTimes = classContext.linesMentionedMultipleTimes(method); for (Location loc : derefLocationSet) { int lineNumber = table.getSourceLine(loc.getHandle().getPosition()); if (lineNumber > 0 && !linesMentionedMultipleTimes.get(lineNumber)) { uniqueDereferenceLocations = true; } } } return uniqueDereferenceLocations; }
/** * Factory method for creating a source line annotation describing the * source line numbers for a range of instruction in a method. * * @param classContext * theClassContext * @param methodGen * the method * @param start * the start instruction * @param end * the end instruction (inclusive) */ public static SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) { LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool()); String className = methodGen.getClassName(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, start.getPosition(), end.getPosition()); } int startLine = lineNumberTable.getSourceLine(start.getPosition()); int endLine = lineNumberTable.getSourceLine(end.getPosition()); return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition()); }
/** * Create from Method and bytecode offset in a visited class. * * @param jclass * JavaClass of visited class * @param method * Method in visited class * @param pc * bytecode offset in visited method * @return SourceLineAnnotation describing visited instruction */ public static SourceLineAnnotation fromVisitedInstruction(JavaClass jclass, Method method, int pc) { LineNumberTable lineNumberTable = method.getCode().getLineNumberTable(); String className = jclass.getClassName(); String sourceFile = jclass.getSourceFileName(); if (lineNumberTable == null) { return createUnknown(className, sourceFile, pc, pc); } int startLine = lineNumberTable.getSourceLine(pc); return new SourceLineAnnotation(className, sourceFile, startLine, startLine, pc, pc); }
int backTarget = branchTarget - 3 + offset; int reg = getCodeByte(branchTarget - 5); int testLineNumber = lineNumbers.getSourceLine(getPC()); int incLineNumber = lineNumbers.getSourceLine(branchTarget - 6); int beforeIncLineNumber = lineNumbers.getSourceLine(branchTarget - 7); if (backTarget < getPC() && getPC() - 8 < backTarget && reg != rMax && incLineNumber < testLineNumber + 3 && beforeIncLineNumber > incLineNumber) {
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, int local, int position1, int position2) { LocalVariableTable localVariableTable = method.getLocalVariableTable(); String localName = UNKNOWN_NAME; if (localVariableTable != null) { LocalVariable lv1 = localVariableTable.getLocalVariable(local, position1); if (lv1 == null) { lv1 = localVariableTable.getLocalVariable(local, position2); position1 = position2; } if (lv1 != null) { localName = lv1.getName(); } } LineNumberTable lineNumbers = method.getLineNumberTable(); if (lineNumbers == null) { return new LocalVariableAnnotation(localName, local, position1); } int line = lineNumbers.getSourceLine(position1); return new LocalVariableAnnotation(localName, local, position1, line); }
boolean split = occurrences > 1; if (lineNumberTable != null) { int line = lineNumberTable.getSourceLine(handle.getPosition()); if (line > 0 && linesMentionedMultipleTimes.get(line)) { split = true;
int startHandlerLinenumber = lineNumbers.getSourceLine(handled);
if (item0.getPC() != -1 && item1.getPC() != -1) { if (lineNumberTable != null) { int line0 = lineNumberTable.getSourceLine(item0.getPC()); int line1 = lineNumberTable.getSourceLine(item1.getPC()); int firstPos = Math.min(item0.getPC(), item1.getPC()); if (firstPos < lastMethodCall && line0 != line1) {
LineNumberTable table = method.getLineNumberTable(); int position = exceptionThrowerHandle.getPosition(); int line = table == null ? 0 : table.getSourceLine(position); while (bbIter.hasNext()) { BasicBlock bb = bbIter.next(); if (ePosition == position || table != null && line == table.getSourceLine(ePosition)) {
int first = table.getSourceLine(putFieldPC); int second = table.getSourceLine(getPC()); if (first + 1 != second && first != second) { break checkPUTFIELD;
IsNullValue v = frame.getValue(index); if (!v.isDefinitelyNull()) { int sourceLine = lineNumbers.getSourceLine(handle.getPosition()); if (sourceLine > 0) { linesWithLoadsOfNotDefinitelyNullValues.set(sourceLine);
private static int getLineNumber(Method method, InstructionHandle handle) { LineNumberTable table = method.getCode().getLineNumberTable(); if (table == null) { return -1; } return table.getSourceLine(handle.getPosition()); } }