Package edu.umd.cs.findbugs.detect
Class FindDeadLocalStores
- java.lang.Object
-
- edu.umd.cs.findbugs.detect.FindDeadLocalStores
-
- All Implemented Interfaces:
Detector
,Priorities
public class FindDeadLocalStores extends java.lang.Object implements Detector
Find dead stores to local variables.
-
-
Field Summary
Fields Modifier and Type Field Description private BugReporter
bugReporter
private static boolean
DEBUG
private static java.util.BitSet
defensiveConstantValueOpcodes
Opcodes of instructions that load constant values that often indicate defensive programming.private static java.util.Set<java.lang.String>
EXCLUDED_LOCALS
private static java.lang.String
FINDBUGS_EXCLUDED_LOCALS_PROP_NAME
private static boolean
SUPPRESS_IF_AT_LEAST_ONE_LIVE_STORE_ON_LINE
System property to enable a feature that suppresses warnings if there is at least one live store on the line where the warning would be reported.-
Fields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description FindDeadLocalStores(BugReporter bugReporter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method)
private void
countLocalStoresLoadsAndIncrements(int[] localStoreCount, int[] localLoadCount, int[] localIncrementCount, CFG cfg)
Count stores, loads, and increments of local variables in method whose CFG is given.private boolean
isLoad(Location location)
Is instruction at given location a load?private boolean
isStore(Location location)
Is instruction at given location a store?private boolean
prescreen(ClassContext classContext, org.apache.bcel.classfile.Method method)
void
report()
This method is called after all classes to be visited.private void
suppressWarningsIfOneLiveStoreOnLine(BugAccumulator accumulator, java.util.BitSet liveStoreSourceLineSet)
If feature is enabled, suppress warnings where there is at least one live store on the line where the warning would be reported.void
visitClassContext(ClassContext classContext)
Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
-
FINDBUGS_EXCLUDED_LOCALS_PROP_NAME
private static final java.lang.String FINDBUGS_EXCLUDED_LOCALS_PROP_NAME
- See Also:
- Constant Field Values
-
EXCLUDED_LOCALS
@StaticConstant private static final java.util.Set<java.lang.String> EXCLUDED_LOCALS
-
SUPPRESS_IF_AT_LEAST_ONE_LIVE_STORE_ON_LINE
private static final boolean SUPPRESS_IF_AT_LEAST_ONE_LIVE_STORE_ON_LINE
System property to enable a feature that suppresses warnings if there is at least one live store on the line where the warning would be reported. Eliminates some FPs due to inlining/duplication of finally blocks. But, kills some legitimate warnings where there are truly multiple stores on the same line.
-
defensiveConstantValueOpcodes
private static final java.util.BitSet defensiveConstantValueOpcodes
Opcodes of instructions that load constant values that often indicate defensive programming.
-
bugReporter
private final BugReporter bugReporter
-
-
Constructor Detail
-
FindDeadLocalStores
public FindDeadLocalStores(BugReporter bugReporter)
-
-
Method Detail
-
prescreen
private boolean prescreen(ClassContext classContext, org.apache.bcel.classfile.Method method)
-
visitClassContext
public void visitClassContext(ClassContext classContext)
Description copied from interface:Detector
Visit the ClassContext for a class which should be analyzed for instances of bug patterns.- Specified by:
visitClassContext
in interfaceDetector
- Parameters:
classContext
- the ClassContext
-
analyzeMethod
private void analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method) throws DataflowAnalysisException, CFGBuilderException
-
suppressWarningsIfOneLiveStoreOnLine
private void suppressWarningsIfOneLiveStoreOnLine(BugAccumulator accumulator, java.util.BitSet liveStoreSourceLineSet)
If feature is enabled, suppress warnings where there is at least one live store on the line where the warning would be reported.- Parameters:
accumulator
- BugAccumulator containing warnings for methodliveStoreSourceLineSet
- bitset of lines where at least one live store was seen
-
countLocalStoresLoadsAndIncrements
private void countLocalStoresLoadsAndIncrements(int[] localStoreCount, int[] localLoadCount, int[] localIncrementCount, CFG cfg)
Count stores, loads, and increments of local variables in method whose CFG is given.- Parameters:
localStoreCount
- counts of local stores (indexed by local)localLoadCount
- counts of local loads (indexed by local)localIncrementCount
- counts of local increments (indexed by local)cfg
- control flow graph (CFG) of method
-
isStore
private boolean isStore(Location location)
Is instruction at given location a store?- Parameters:
location
- the location- Returns:
- true if instruction at given location is a store, false if not
-
isLoad
private boolean isLoad(Location location)
Is instruction at given location a load?- Parameters:
location
- the location- Returns:
- true if instruction at given location is a load, false if not
-
-