Package edu.umd.cs.findbugs.detect
Class StreamResourceTracker
java.lang.Object
edu.umd.cs.findbugs.detect.StreamResourceTracker
- All Implemented Interfaces:
ResourceTracker<Stream>
Resource tracker which determines where streams are created, and how they are
used within the method.
- Author:
- David Hovemeyer
-
Constructor Summary
ConstructorsConstructorDescriptionStreamResourceTracker(StreamFactory[] streamFactoryList, RepositoryLookupFailureCallback lookupFailureCallback) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStreamEscape(Stream source, Location target) Indicate that a stream escapes at the given target Location.voidaddStreamOpenLocation(Location streamOpenLocation, Stream stream) Indicate that a stream is constructed at this Location.createVisitor(Stream resource, org.apache.bcel.generic.ConstantPoolGen cpg) Create a ResourceValueFrameModelingVisitor to model the effect of instructions on the state of the resource.getStreamEquivalenceClass(Stream stream) Get the equivalence class for given stream.booleanignoreExceptionEdge(Edge edge, Stream resource, org.apache.bcel.generic.ConstantPoolGen cpg) Determine whether the analysis should ignore given exception edge.booleanignoreImplicitExceptions(Stream resource) Determine whether the analysis should ignore exception edges on which only implicit exceptions are propagated.booleanisParamInstance(Stream resource, int slot) Return if the given parameter slot contains the resource instance upon entry to the method.booleanisResourceClose(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, Stream 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.booleanisResourceOpen(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, Stream resource, ResourceValueFrame frame) booleanisUninterestingStreamEscape(Stream stream) Determine if an uninteresting stream escapes at given location.voidTransitively mark all streams into which uninteresting streams (such as System.out) escape.booleanmightCloseResource(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.voidsetResourceCollection(ResourceCollection<Stream> resourceCollection) Set the precomputed ResourceCollection for the method.
-
Constructor Details
-
StreamResourceTracker
public StreamResourceTracker(StreamFactory[] streamFactoryList, RepositoryLookupFailureCallback lookupFailureCallback) Constructor.- Parameters:
streamFactoryList- array of StreamFactory objects which determine where streams are createdlookupFailureCallback- used when class hierarchy lookups fail
-
-
Method Details
-
setResourceCollection
Set the precomputed ResourceCollection for the method. -
addStreamEscape
Indicate that a stream escapes at the given target Location.- Parameters:
source- the Stream that is escapingtarget- the target Location (where the stream escapes)
-
markTransitiveUninterestingStreamEscapes
public void markTransitiveUninterestingStreamEscapes()Transitively mark all streams into which uninteresting streams (such as System.out) escape. This handles the rule that wrapping an uninteresting stream makes the wrapper uninteresting as well. -
isUninterestingStreamEscape
Determine if an uninteresting stream escapes at given location. markTransitiveUninterestingStreamEscapes() should be called first.- Parameters:
stream- the stream- Returns:
- true if an uninteresting stream escapes at the location
-
addStreamOpenLocation
Indicate that a stream is constructed at this Location.- Parameters:
streamOpenLocation- the Locationstream- the Stream opened at this Location
-
getStreamEquivalenceClass
Get the equivalence class for given stream. May only be called if markTransitiveUninterestingStreamEscapes() has been called.- Parameters:
stream- the stream- Returns:
- the set containing the equivalence class for the given stream
-
isResourceCreation
public Stream isResourceCreation(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg) Description copied from interface:ResourceTrackerDetermine if the given instruction is the site where a resource is created.- Specified by:
isResourceCreationin interfaceResourceTracker<Stream>- 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
-
isResourceOpen
public boolean isResourceOpen(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, Stream resource, ResourceValueFrame frame) -
isResourceClose
public boolean isResourceClose(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, Stream resource, ResourceValueFrame frame) Description copied from interface:ResourceTrackerDetermine if the given instruction is the site where a resource is closed.- Specified by:
isResourceClosein interfaceResourceTracker<Stream>- 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
-
mightCloseResource
public boolean mightCloseResource(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException Description copied from interface:ResourceTrackerDetermine if the given instruction is the site where a resource is closed.- Specified by:
mightCloseResourcein interfaceResourceTracker<Stream>- 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
public ResourceValueFrameModelingVisitor createVisitor(Stream resource, org.apache.bcel.generic.ConstantPoolGen cpg) Description copied from interface:ResourceTrackerCreate a ResourceValueFrameModelingVisitor to model the effect of instructions on the state of the resource.- Specified by:
createVisitorin interfaceResourceTracker<Stream>- Parameters:
resource- the resource we are trackingcpg- the ConstantPoolGen of the method- Returns:
- a ResourceValueFrameModelingVisitor
-
ignoreImplicitExceptions
Description copied from interface:ResourceTrackerDetermine 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.- Specified by:
ignoreImplicitExceptionsin interfaceResourceTracker<Stream>- Parameters:
resource- the resource being tracked- Returns:
- true if implicit exceptions are significant, false if they should be ignore
-
ignoreExceptionEdge
public boolean ignoreExceptionEdge(Edge edge, Stream resource, org.apache.bcel.generic.ConstantPoolGen cpg) Description copied from interface:ResourceTrackerDetermine whether the analysis should ignore given exception edge. This allows the analysis to customize which kinds of exceptions are significant.- Specified by:
ignoreExceptionEdgein interfaceResourceTracker<Stream>- Parameters:
edge- the exception edgeresource- the resourcecpg- the ConstantPoolGen- Returns:
- true if exception edge should be ignored, false if it should be considered
-
isParamInstance
Description copied from interface:ResourceTrackerReturn if the given parameter slot contains the resource instance upon entry to the method. This is for resources passed as parameters.- Specified by:
isParamInstancein interfaceResourceTracker<Stream>- Parameters:
resource- the resourceslot- the local variable slot- Returns:
- true if the slot contains the resource instance, false otherwise
-