SourceLineAnnotation asSourceLineAnnotation() { return SourceLineAnnotation.fromVisitedInstruction(methodDescriptor, position); }
private void accumulateBug() { if (pendingBug == null) { return; } bugAccumulator.accumulateBug(pendingBug, SourceLineAnnotation.fromVisitedInstruction(this, monitorEnterPC)); pendingBug = null; } }
/** * Accumulate a warning at source location currently being visited by given * BytecodeScanningDetector. * * @param bug * the warning * @param visitor * the BytecodeScanningDetector */ public void accumulateBug(BugInstance bug, BytecodeScanningDetector visitor) { SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(visitor); accumulateBug(bug, source); }
/** * Create from Method and Location in a visited class. * * @param classContext * ClassContext of visited class * @param method * Method in visited class * @param loc * Location in visited class * @return SourceLineAnnotation describing visited Location */ public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, Location loc) { return fromVisitedInstruction(classContext, method, loc.getHandle()); }
/** * Create from Method and bytecode offset in a visited class. * * @param classContext * ClassContext 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(ClassContext classContext, Method method, int pc) { return fromVisitedInstruction(classContext.getJavaClass(), method, pc); }
public SourceLineAnnotation getSourceLineAnnotation() { return SourceLineAnnotation.fromVisitedInstruction(method.getMethodDescriptor(), pc); }
public void accumulateBug(BugInstance bug, ClassContext classContext, Method method, Location location) { accumulateBug(bug, SourceLineAnnotation.fromVisitedInstruction(classContext, method, location)); }
/** * Create from Method and InstructionHandle in a visited class. * * @param classContext * ClassContext of visited class * @param method * Method in visited class * @param handle * InstructionHandle in visited class * @return SourceLineAnnotation describing visited instruction */ public static SourceLineAnnotation fromVisitedInstruction(ClassContext classContext, Method method, InstructionHandle handle) { return fromVisitedInstruction(classContext, method, handle.getPosition()); }
/** * Add a source line annotation for instruction currently being visited by * given visitor. Note that if the method does not have line number * information, then no source line annotation will be added. * * @param visitor * a BytecodeScanningDetector visitor that is currently visiting * the instruction * @return this object */ @Nonnull public BugInstance addSourceLine(BytecodeScanningDetector visitor) { SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(visitor); if (sourceLineAnnotation != null) { add(sourceLineAnnotation); } return this; }
/** * Add a source line annotation for instruction whose PC is given in the * method that the given visitor is currently visiting. Note that if the * method does not have line number information, then no source line * annotation will be added. * * @param classContext * the ClassContext * @param visitor * a PreorderVisitor that is currently visiting the method * @param pc * bytecode offset of the instruction * @return this object */ @Nonnull public BugInstance addSourceLine(ClassContext classContext, PreorderVisitor visitor, int pc) { SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, visitor, pc); if (sourceLineAnnotation != null) { add(sourceLineAnnotation); } return this; }
/** * Factory method for creating a source line annotation describing the * source line number for the instruction being visited by given visitor. * * @param visitor * a DismantleBytecode visitor which is visiting the method * @return the SourceLineAnnotation, or null if we do not have line number * information for the instruction */ public static SourceLineAnnotation fromVisitedInstruction(BytecodeScanningDetector visitor) { return fromVisitedInstruction(visitor.getClassContext(), visitor, visitor.getPC()); }
public void accumulateBug(BugInstance bug, ClassContext classContext, MethodGen methodGen, String sourceFile, Location location) { accumulateBug(bug, SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, location.getHandle())); } }
/** * Create from MethodDescriptor and Location of visited instruction. * * @param methodDescriptor * MethodDescriptor identifying analyzed method * @param location * Location of instruction within analyed method * @return SourceLineAnnotation describing visited instruction */ public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, Location location) { return fromVisitedInstruction(methodDescriptor, location.getHandle().getPosition()); }
/** * Add source line annotation for given Location in a method. * * @param classContext * the ClassContext * @param method * the Method * @param handle * InstructionHandle of an instruction in the method * @return this BugInstance */ @Nonnull public BugInstance addSourceLine(ClassContext classContext, Method method, InstructionHandle handle) { SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, method, handle.getPosition()); if (sourceLineAnnotation != null) { add(sourceLineAnnotation); } return this; }
@Override public void sawOpcode(int seen) { switch (seen) { case Const.ACONST_NULL: nullOnTOS = true; return; case Const.ARETURN: if (nullOnTOS) { SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, getPC()); if (sourceLineAnnotation != null) { found.add(sourceLineAnnotation); } } break; default: break; } nullOnTOS = false; } }
/** * Add a source line annotation for instruction whose PC is given in the * method that the given visitor is currently visiting. Note that if the * method does not have line number information, then no source line * annotation will be added. * * @param visitor * a BytecodeScanningDetector that is currently visiting the * method * @param pc * bytecode offset of the instruction * @return this object */ @Nonnull public BugInstance addSourceLine(BytecodeScanningDetector visitor, int pc) { SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(visitor.getClassContext(), visitor, pc); if (sourceLineAnnotation != null) { add(sourceLineAnnotation); } return this; }
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); }
public static SourceLineAnnotation fromVisitedInstruction(MethodDescriptor methodDescriptor, int position) { try { IAnalysisCache analysisCache = Global.getAnalysisCache(); JavaClass jclass = analysisCache.getClassAnalysis(JavaClass.class, methodDescriptor.getClassDescriptor()); Method method = analysisCache.getMethodAnalysis(Method.class, methodDescriptor); return fromVisitedInstruction(jclass, method, position); } catch (CheckedAnalysisException e) { return createReallyUnknown(methodDescriptor.getClassDescriptor().toDottedClassName()); } }
@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; } } }
@Override public void visit(LocalVariable obj) { if (isReservedName(obj.getName())) { LocalVariableAnnotation var = new LocalVariableAnnotation(obj.getName(), obj.getIndex(), obj.getStartPC()); SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, obj.getStartPC()); BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", NORMAL_PRIORITY) .addClassAndMethod(this).add(var).add(source); bugReporter.reportBug(bug); } }