edu.umd.cs.findbugs

Class ByteCodePatternDetector

public abstract class ByteCodePatternDetector extends Object implements Detector

A base class for bug detectors that are based on a ByteCodePattern. ByteCodePatterns provide an easy way to detect patterns of bytecode instructions, taking into account control flow and uses of fields and values.

See Also: ByteCodePattern

Method Summary
protected abstract BugReportergetBugReporter()
abstract ByteCodePatterngetPattern()
Get the ByteCodePattern for this detector.
abstract booleanprescreen(Method method, ClassContext classContext)
Prescreen a method.
voidreport()
abstract voidreportMatch(ClassContext classContext, Method method, ByteCodePatternMatch match)
Called to report an instance of the ByteCodePattern.
voidvisitClassContext(ClassContext classContext)

Method Detail

getBugReporter

protected abstract BugReporter getBugReporter()

getPattern

public abstract ByteCodePattern getPattern()
Get the ByteCodePattern for this detector.

prescreen

public abstract boolean prescreen(Method method, ClassContext classContext)
Prescreen a method. It is a valid, but dumb, implementation simply to return true unconditionally. A better implementation is to call ClassContext.getBytecodeSet() to check whether the method actually contains the bytecode instructions that the pattern will look for. The theory is that checking the bytecode set is very fast, while building the MethodGen, CFG, ValueNumberAnalysis, etc. objects required to match ByteCodePatterns is slow, and the bytecode pattern matching algorithm is also not particularly fast.

As a datapoint, prescreening speeds up the BCPDoubleCheck detector by a factor of 5 with no loss of generality and only a dozen or so extra lines of code.

Parameters: method the method classContext the ClassContext for the method

Returns: true if the method should be analyzed for instances of the ByteCodePattern

report

public void report()

reportMatch

public abstract void reportMatch(ClassContext classContext, Method method, ByteCodePatternMatch match)
Called to report an instance of the ByteCodePattern.

Parameters: classContext the ClassContext for the analyzed class method the method to instance appears in match the ByteCodePatternMatch object representing the match of the ByteCodePattern against actual instructions in the method

visitClassContext

public void visitClassContext(ClassContext classContext)
FindBugs™ is licenced under the LGPL. Copyright © 2006 University of Maryland.