Package edu.umd.cs.findbugs.ba.obl
Class ObligationAnalysis
java.lang.Object
edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis<StateSet>
edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<StateSet>
edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis<StateSet>
edu.umd.cs.findbugs.ba.obl.ObligationAnalysis
- All Implemented Interfaces:
DataflowAnalysis<StateSet>
Dataflow analysis to track obligations (i/o streams and other resources which
must be closed).
See Weimer and Necula, Finding and preventing run-time error handling mistakes, OOPSLA 2004.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final InstructionActionCache
private StateSet
private final ObligationPolicyDatabase
private static final boolean
private static final boolean
private final IErrorLogger
private final ObligationFactory
private final IsNullValueDataflow
private static final org.slf4j.Logger
private final TypeDataflow
(package private) static final ClassDescriptor
private final XMethod
-
Constructor Summary
ConstructorsConstructorDescriptionObligationAnalysis
(DepthFirstSearch dfs, XMethod xmethod, org.apache.bcel.generic.ConstantPoolGen cpg, ObligationFactory factory, ObligationPolicyDatabase database, TypeDataflow typeDataflow, IsNullValueDataflow invDataflow, IErrorLogger errorLogger) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.bcel.generic.Type
acmpNullCheck
(short opcode, Edge edge, org.apache.bcel.generic.InstructionHandle last, BasicBlock sourceBlock) private Obligation
void
Copy dataflow facts.Create empty (uninitialized) dataflow facts for one program point.void
edgeTransfer
(Edge edge, StateSet fact) Edge transfer function.private void
endTransfer
(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, StateSet result) void
initEntryFact
(StateSet fact) Initialize the "entry" fact for the graph.boolean
isFactValid
(StateSet fact) Determine whether the given fact is valid (neither top nor bottom).private boolean
isPossibleIfComparison
(Edge edge) boolean
Is the given fact the top value.void
makeFactTop
(StateSet fact) Make given fact the top value.void
Meet a dataflow fact associated with an incoming edge into another fact.private org.apache.bcel.generic.Type
nullCheck
(short opcode, Edge edge, org.apache.bcel.generic.InstructionHandle last, BasicBlock sourceBlock) boolean
Are given dataflow facts the same?void
transfer
(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, StateSet start, StateSet result) Transfer function for the analysis.void
transferInstruction
(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, StateSet fact) Transfer function for a single instruction.Methods inherited from class edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis
getBlockOrder, getDepthFirstSearch, isForwards
Methods inherited from class edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis
getFactAfterLocation, getFactAtLocation
Methods inherited from class edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis
factToString, finishIteration, getFactOnEdge, getLastUpdateTimestamp, getResultFact, getStartFact, resultFactIterator, setLastUpdateTimestamp, startIteration
-
Field Details
-
DEBUG
private static final boolean DEBUG -
DEBUG_NULL_CHECK
private static final boolean DEBUG_NULL_CHECK -
xmethod
-
factory
-
database
-
typeDataflow
-
invDataflow
-
errorLogger
-
actionCache
-
cachedEntryFact
-
willClose
-
LOG
private static final org.slf4j.Logger LOG
-
-
Constructor Details
-
ObligationAnalysis
public ObligationAnalysis(DepthFirstSearch dfs, XMethod xmethod, org.apache.bcel.generic.ConstantPoolGen cpg, ObligationFactory factory, ObligationPolicyDatabase database, TypeDataflow typeDataflow, IsNullValueDataflow invDataflow, IErrorLogger errorLogger) Constructor.- Parameters:
dfs
- a DepthFirstSearch on the method to be analyzedxmethod
- method to analyzecpg
- ConstantPoolGen of the method to be analyzedfactory
- the ObligationFactory defining the obligation typesdatabase
- the PolicyDatabase defining the methods which add and delete obligationserrorLogger
- callback to use when reporting missing classes
-
-
Method Details
-
getActionCache
-
createFact
Description copied from interface:DataflowAnalysis
Create empty (uninitialized) dataflow facts for one program point. A valid value will be copied into it before it is used. -
isFactValid
Description copied from class:AbstractDataflowAnalysis
Determine whether the given fact is valid (neither top nor bottom).- Specified by:
isFactValid
in classAbstractDataflowAnalysis<StateSet>
-
transferInstruction
public void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, StateSet fact) throws DataflowAnalysisException Description copied from class:AbstractDataflowAnalysis
Transfer function for a single instruction.- Specified by:
transferInstruction
in classAbstractDataflowAnalysis<StateSet>
- Parameters:
handle
- the instructionbasicBlock
- the BasicBlock containing the instruction; needed to disambiguate instructions in inlined JSR subroutinesfact
- which should be modified based on the instruction- Throws:
DataflowAnalysisException
-
transfer
public void transfer(BasicBlock basicBlock, @CheckForNull org.apache.bcel.generic.InstructionHandle end, StateSet start, StateSet result) throws DataflowAnalysisException Description copied from interface:DataflowAnalysis
Transfer function for the analysis. Taking dataflow facts at start (which might be either the entry or exit of the block, depending on whether the analysis is forwards or backwards), modify result to be the facts at the other end of the block.- Specified by:
transfer
in interfaceDataflowAnalysis<StateSet>
- Overrides:
transfer
in classAbstractDataflowAnalysis<StateSet>
- Parameters:
basicBlock
- the basic blockend
- if nonnull, stop before considering this instruction; otherwise, consider all of the instructions in the basic blockstart
- dataflow facts at beginning of block (if forward analysis) or end of block (if backwards analysis)result
- resulting dataflow facts at other end of block- Throws:
DataflowAnalysisException
-
endTransfer
private void endTransfer(BasicBlock basicBlock, @CheckForNull org.apache.bcel.generic.InstructionHandle end, StateSet result) -
edgeTransfer
Description copied from interface:DataflowAnalysis
Edge transfer function. Modify the given fact that is true on the (logical) edge source to modify it so that it is true at the (logical) edge target.A do-nothing implementation is legal, and appropriate for analyses where branches are not significant.
- Specified by:
edgeTransfer
in interfaceDataflowAnalysis<StateSet>
- Overrides:
edgeTransfer
in classBasicAbstractDataflowAnalysis<StateSet>
- Parameters:
edge
- the Edgefact
- a dataflow fact- Throws:
DataflowAnalysisException
-
isPossibleIfComparison
-
comparesObligationTypeToNull
- Throws:
DataflowAnalysisException
-
nullCheck
private org.apache.bcel.generic.Type nullCheck(short opcode, Edge edge, org.apache.bcel.generic.InstructionHandle last, BasicBlock sourceBlock) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
acmpNullCheck
private org.apache.bcel.generic.Type acmpNullCheck(short opcode, Edge edge, org.apache.bcel.generic.InstructionHandle last, BasicBlock sourceBlock) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
copy
Description copied from interface:DataflowAnalysis
Copy dataflow facts. -
initEntryFact
Description copied from interface:DataflowAnalysis
Initialize the "entry" fact for the graph.- Throws:
DataflowAnalysisException
-
makeFactTop
Description copied from interface:DataflowAnalysis
Make given fact the top value. -
isTop
Description copied from interface:DataflowAnalysis
Is the given fact the top value. -
same
Description copied from interface:DataflowAnalysis
Are given dataflow facts the same? -
meetInto
Description copied from interface:DataflowAnalysis
Meet a dataflow fact associated with an incoming edge into another fact. This is used to determine the start fact for a basic block.- Parameters:
fact
- the predecessor fact (incoming edge)edge
- the edge from the predecessorresult
- the result fact- Throws:
DataflowAnalysisException
-