edu.umd.cs.findbugs.detect
Class FindOpenStream

java.lang.Object
  extended by edu.umd.cs.findbugs.ResourceTrackingDetector<Stream,StreamResourceTracker>
      extended by edu.umd.cs.findbugs.detect.FindOpenStream
All Implemented Interfaces:
Detector

public class FindOpenStream
extends ResourceTrackingDetector<Stream,StreamResourceTracker>

A Detector to look for streams that are opened in a method, do not escape the method, and are not closed on all paths out of the method. Note that "stream" is a bit misleading, since we also use the detector to look for database resources that aren't closed.

Author:
David Hovemeyer

Nested Class Summary
private static class FindOpenStream.PotentialOpenStream
           
 
Field Summary
(package private) static boolean DEBUG
           
(package private) static boolean IGNORE_WRAPPED_UNINTERESTING_STREAMS
           
private  java.util.List<FindOpenStream.PotentialOpenStream> potentialOpenStreamList
           
(package private) static org.apache.bcel.generic.ObjectType[] streamBaseList
          List of base classes of tracked resources.
(package private) static StreamFactory[] streamFactoryList
          StreamFactory objects used to detect resources created within analyzed methods.
 
Fields inherited from class edu.umd.cs.findbugs.ResourceTrackingDetector
bugReporter
 
Fields inherited from interface edu.umd.cs.findbugs.Detector
EXP_PRIORITY, HIGH_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
 
Constructor Summary
FindOpenStream(BugReporter bugReporter)
           
 
Method Summary
 void analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method, StreamResourceTracker resourceTracker, ResourceCollection<Stream> resourceCollection)
           
 StreamResourceTracker getResourceTracker(ClassContext classContext, org.apache.bcel.classfile.Method method)
           
 void inspectResult(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.generic.MethodGen methodGen, CFG cfg, Dataflow<ResourceValueFrame,ResourceValueAnalysis<Stream>> dataflow, Stream stream)
           
static boolean isMainMethod(org.apache.bcel.classfile.Method method)
           
static void main(java.lang.String[] argv)
           
 boolean prescreen(ClassContext classContext, org.apache.bcel.classfile.Method method)
           
 
Methods inherited from class edu.umd.cs.findbugs.ResourceTrackingDetector
getAnalysisContext, report, setAnalysisContext, visitClassContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

static final boolean DEBUG

IGNORE_WRAPPED_UNINTERESTING_STREAMS

static final boolean IGNORE_WRAPPED_UNINTERESTING_STREAMS

streamBaseList

static final org.apache.bcel.generic.ObjectType[] streamBaseList
List of base classes of tracked resources.


streamFactoryList

static final StreamFactory[] streamFactoryList
StreamFactory objects used to detect resources created within analyzed methods.


potentialOpenStreamList

private java.util.List<FindOpenStream.PotentialOpenStream> potentialOpenStreamList
Constructor Detail

FindOpenStream

public FindOpenStream(BugReporter bugReporter)
Method Detail

prescreen

public boolean prescreen(ClassContext classContext,
                         org.apache.bcel.classfile.Method method)
Specified by:
prescreen in class ResourceTrackingDetector<Stream,StreamResourceTracker>

getResourceTracker

public StreamResourceTracker getResourceTracker(ClassContext classContext,
                                                org.apache.bcel.classfile.Method method)
Specified by:
getResourceTracker in class ResourceTrackingDetector<Stream,StreamResourceTracker>

isMainMethod

public static boolean isMainMethod(org.apache.bcel.classfile.Method method)

analyzeMethod

public void analyzeMethod(ClassContext classContext,
                          org.apache.bcel.classfile.Method method,
                          StreamResourceTracker resourceTracker,
                          ResourceCollection<Stream> resourceCollection)
                   throws CFGBuilderException,
                          DataflowAnalysisException
Overrides:
analyzeMethod in class ResourceTrackingDetector<Stream,StreamResourceTracker>
Throws:
CFGBuilderException
DataflowAnalysisException

inspectResult

public void inspectResult(org.apache.bcel.classfile.JavaClass javaClass,
                          org.apache.bcel.generic.MethodGen methodGen,
                          CFG cfg,
                          Dataflow<ResourceValueFrame,ResourceValueAnalysis<Stream>> dataflow,
                          Stream stream)
Specified by:
inspectResult in class ResourceTrackingDetector<Stream,StreamResourceTracker>

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Throws:
java.lang.Exception