Package edu.umd.cs.findbugs.ba
Interface ResourceTracker<Resource>
- All Known Implementing Classes:
StreamResourceTracker
public interface ResourceTracker<Resource>
A ResourceTracker is used with ResourceValueAnalysis to determine where in a
method a certain kind of resource is created, and to model the effect of
instructions on the state of that resource.
- Author:
- David Hovemeyer
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncreateVisitor
(Resource resource, org.apache.bcel.generic.ConstantPoolGen cpg) Create a ResourceValueFrameModelingVisitor to model the effect of instructions on the state of the resource.boolean
ignoreExceptionEdge
(Edge edge, Resource resource, org.apache.bcel.generic.ConstantPoolGen cpg) Determine whether the analysis should ignore given exception edge.boolean
ignoreImplicitExceptions
(Resource resource) Determine whether the analysis should ignore exception edges on which only implicit exceptions are propagated.boolean
isParamInstance
(Resource resource, int slot) Return if the given parameter slot contains the resource instance upon entry to the method.boolean
isResourceClose
(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, Resource resource, ResourceValueFrame frame) Determine if the given instruction is the site where a resource is closed.isResourceCreation
(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg) Determine if the given instruction is the site where a resource is created.boolean
mightCloseResource
(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg) Determine if the given instruction is the site where a resource is closed.
-
Method Details
-
isResourceCreation
Resource isResourceCreation(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException Determine if the given instruction is the site where a resource is created.- Parameters:
basicBlock
- basic block containing the instructionhandle
- the instructioncpg
- the ConstantPoolGen for the method- Returns:
- an opaque Resource object if it is a creation site, or null if it is not a creation site
- Throws:
DataflowAnalysisException
-
isResourceClose
boolean isResourceClose(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, Resource resource, ResourceValueFrame frame) throws DataflowAnalysisException Determine if the given instruction is the site where a resource is closed.- Parameters:
basicBlock
- basic block containing the instructionhandle
- the instructioncpg
- the ConstantPoolGen for the methodresource
- the resource, as returned by isResourceCreation()frame
- the ResourceValueFrame representing the stack prior to executing the instruction- Returns:
- true if the resource is closed here, false otherwise
- Throws:
DataflowAnalysisException
-
mightCloseResource
boolean mightCloseResource(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException Determine if the given instruction is the site where a resource is closed.- Parameters:
basicBlock
- basic block containing the instructionhandle
- the instructioncpg
- the ConstantPoolGen for the method- Returns:
- true if the resource is closed here, false otherwise
- Throws:
DataflowAnalysisException
-
createVisitor
ResourceValueFrameModelingVisitor createVisitor(Resource resource, org.apache.bcel.generic.ConstantPoolGen cpg) Create a ResourceValueFrameModelingVisitor to model the effect of instructions on the state of the resource.- Parameters:
resource
- the resource we are trackingcpg
- the ConstantPoolGen of the method- Returns:
- a ResourceValueFrameModelingVisitor
-
ignoreImplicitExceptions
Determine whether the analysis should ignore exception edges on which only implicit exceptions are propagated. This allows different resource types to be tracked with varying precision. For example, we might want to ignore implicit exceptions for stream objects, but treat them as significant for database resources.- Parameters:
resource
- the resource being tracked- Returns:
- true if implicit exceptions are significant, false if they should be ignore
-
ignoreExceptionEdge
boolean ignoreExceptionEdge(Edge edge, Resource resource, org.apache.bcel.generic.ConstantPoolGen cpg) Determine whether the analysis should ignore given exception edge. This allows the analysis to customize which kinds of exceptions are significant.- Parameters:
edge
- the exception edgeresource
- the resourcecpg
- the ConstantPoolGen- Returns:
- true if exception edge should be ignored, false if it should be considered
-
isParamInstance
Return if the given parameter slot contains the resource instance upon entry to the method. This is for resources passed as parameters.- Parameters:
resource
- the resourceslot
- the local variable slot- Returns:
- true if the slot contains the resource instance, false otherwise
-