Class ByteCodePatternDetector
java.lang.Object
edu.umd.cs.findbugs.ByteCodePatternDetector
- All Implemented Interfaces:
Detector, Priorities
- Direct Known Subclasses:
LazyInit
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate static final StringFields inherited from interface Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> Stream<T> createStream(Iterator<T> iter) protected abstract BugReporterprivate Stringabstract ByteCodePatternGet the ByteCodePattern for this detector.abstract booleanprescreen(org.apache.bcel.classfile.Method method, ClassContext classContext) Prescreen a method.voidreport()This method is called after all classes to be visited.abstract voidreportMatch(ClassContext classContext, org.apache.bcel.classfile.Method method, ByteCodePatternMatch match) Called to report an instance of the ByteCodePattern.voidvisitClassContext(ClassContext classContext) Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
METHOD
-
-
Constructor Details
-
ByteCodePatternDetector
public ByteCodePatternDetector()
-
-
Method Details
-
getBugReporter
-
visitClassContext
Description copied from interface:DetectorVisit the ClassContext for a class which should be analyzed for instances of bug patterns.- Specified by:
visitClassContextin interfaceDetector- Parameters:
classContext- the ClassContext
-
createStream
-
getDetectorName
-
report
-
getPattern
Get the ByteCodePattern for this detector. -
prescreen
public abstract boolean prescreen(org.apache.bcel.classfile.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 methodclassContext- the ClassContext for the method- Returns:
- true if the method should be analyzed for instances of the ByteCodePattern
-
reportMatch
public abstract void reportMatch(ClassContext classContext, org.apache.bcel.classfile.Method method, ByteCodePatternMatch match) throws CFGBuilderException, DataflowAnalysisException Called to report an instance of the ByteCodePattern.- Parameters:
classContext- the ClassContext for the analyzed classmethod- the method to instance appears inmatch- the ByteCodePatternMatch object representing the match of the ByteCodePattern against actual instructions in the method- Throws:
CFGBuilderExceptionDataflowAnalysisException
-