Package edu.umd.cs.findbugs.ba.npe
Class NullDerefAndRedundantComparisonFinder
- java.lang.Object
-
- edu.umd.cs.findbugs.ba.npe.NullDerefAndRedundantComparisonFinder
-
public class NullDerefAndRedundantComparisonFinder extends java.lang.Object
A user-friendly front end for finding null pointer dereferences and redundant null comparisons.- See Also:
IsNullValueAnalysis
-
-
Field Summary
Fields Modifier and Type Field Description private AssertionMethods
assertionMethods
private ClassContext
classContext
private NullDerefAndRedundantComparisonCollector
collector
private static boolean
DEBUG
private static boolean
DEBUG_DEREFS
private java.util.BitSet
definitelyDifferentBranchSet
private java.util.BitSet
definitelySameBranchSet
private boolean
findGuaranteedDerefs
private IsNullValueDataflow
invDataflow
private java.util.BitSet
lineMentionedMultipleTimes
private org.apache.bcel.classfile.Method
method
private static boolean
MY_DEBUG
private static boolean
PRUNE_GUARANTEED_DEREFERENCES
private java.util.List<RedundantBranch>
redundantBranchList
private java.util.BitSet
undeterminedBranchSet
private UnconditionalValueDerefDataflow
uvdDataflow
private ValueNumberDataflow
vnaDataflow
-
Constructor Summary
Constructors Constructor Description NullDerefAndRedundantComparisonFinder(ClassContext classContext, org.apache.bcel.classfile.Method method, NullDerefAndRedundantComparisonCollector collector)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private void
analyzeIfNullBranch(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle lastHandle)
This is called for both IFNULL and IFNONNULL instructions.private void
analyzeNullCheck(IsNullValueDataflow invDataflow, BasicBlock basicBlock)
private void
analyzeRefComparisonBranch(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle lastHandle)
void
checkEdges(CFG cfg, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugEdgeLocationMap)
private void
checkForUnconditionallyDereferencedNullValues(Location thisLocation, java.util.Map<ValueNumber,java.util.SortedSet<Location>> knownNullAndDoomedAt, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, ValueNumberFrame vnaFrame, IsNullValueFrame invFrame, UnconditionalValueDerefSet derefSet, boolean isEdge)
Check for unconditionally dereferenced null values at a particular location in the CFG.private void
examineBasicBlocks()
Examine basic blocks for null checks and potentially-redundant null comparisons.private void
examineNullValues()
Examine null values.private void
examineRedundantBranches()
Examine redundant branches.void
execute()
static BugAnnotation
findAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
static FieldAnnotation
findFieldAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
static LocalVariableAnnotation
findLocalAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
java.util.Map<ValueNumber,java.util.Set<Location>>
findNullAssignments(java.util.Set<LocationWhereValueBecomesNull> locationWhereValueBecomesNullSet)
static XField
findXFieldFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
Deprecated.private static int
getLineNumber(org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle)
private void
noteUnconditionallyDereferencedNullValue(Location thisLocation, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugLocations, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, UnconditionalValueDerefSet derefSet, IsNullValue isNullValue, ValueNumber valueNumber)
Note the locations where a known-null value is unconditionally dereferenced.private void
removeStrictlyDominatedLocations(java.util.Set<Location> locations, DominatorsAnalysis domAnalysis)
private void
removeStrictlyPostDominatedLocations(java.util.Set<Location> locations, PostDominatorsAnalysis postDomAnalysis)
void
reportBugs(java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, java.util.HashSet<ValueNumber> npeIfStatementCovered, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugLocationMap, java.util.Map<ValueNumber,java.util.Set<Location>> nullValueAssignmentMap)
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
-
PRUNE_GUARANTEED_DEREFERENCES
private static final boolean PRUNE_GUARANTEED_DEREFERENCES
-
DEBUG_DEREFS
private static final boolean DEBUG_DEREFS
-
classContext
private final ClassContext classContext
-
method
private final org.apache.bcel.classfile.Method method
-
collector
private final NullDerefAndRedundantComparisonCollector collector
-
findGuaranteedDerefs
private final boolean findGuaranteedDerefs
-
redundantBranchList
private final java.util.List<RedundantBranch> redundantBranchList
-
definitelySameBranchSet
private final java.util.BitSet definitelySameBranchSet
-
definitelyDifferentBranchSet
private final java.util.BitSet definitelyDifferentBranchSet
-
undeterminedBranchSet
private final java.util.BitSet undeterminedBranchSet
-
lineMentionedMultipleTimes
private final java.util.BitSet lineMentionedMultipleTimes
-
invDataflow
private IsNullValueDataflow invDataflow
-
vnaDataflow
private ValueNumberDataflow vnaDataflow
-
uvdDataflow
private UnconditionalValueDerefDataflow uvdDataflow
-
assertionMethods
private final AssertionMethods assertionMethods
-
MY_DEBUG
private static final boolean MY_DEBUG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NullDerefAndRedundantComparisonFinder
public NullDerefAndRedundantComparisonFinder(ClassContext classContext, org.apache.bcel.classfile.Method method, NullDerefAndRedundantComparisonCollector collector)
Constructor.- Parameters:
classContext
- the ClassContextmethod
- the method to analyzecollector
- the NullDerefAndRedundantComparisonCollector used to report null derefs and redundant null comparisons
-
-
Method Detail
-
execute
public void execute()
-
examineBasicBlocks
private void examineBasicBlocks() throws DataflowAnalysisException, CFGBuilderException
Examine basic blocks for null checks and potentially-redundant null comparisons.
-
examineNullValues
private void examineNullValues() throws CFGBuilderException, DataflowAnalysisException
Examine null values. Report any that are guaranteed to be dereferenced on non-implicit-exception paths.
-
findNullAssignments
public java.util.Map<ValueNumber,java.util.Set<Location>> findNullAssignments(java.util.Set<LocationWhereValueBecomesNull> locationWhereValueBecomesNullSet)
-
reportBugs
public void reportBugs(java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, java.util.HashSet<ValueNumber> npeIfStatementCovered, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugLocationMap, java.util.Map<ValueNumber,java.util.Set<Location>> nullValueAssignmentMap) throws CFGBuilderException, DataflowAnalysisException
-
checkEdges
public void checkEdges(CFG cfg, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugEdgeLocationMap) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
removeStrictlyPostDominatedLocations
private void removeStrictlyPostDominatedLocations(java.util.Set<Location> locations, PostDominatorsAnalysis postDomAnalysis)
-
removeStrictlyDominatedLocations
private void removeStrictlyDominatedLocations(java.util.Set<Location> locations, DominatorsAnalysis domAnalysis)
-
checkForUnconditionallyDereferencedNullValues
private void checkForUnconditionallyDereferencedNullValues(Location thisLocation, java.util.Map<ValueNumber,java.util.SortedSet<Location>> knownNullAndDoomedAt, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, ValueNumberFrame vnaFrame, IsNullValueFrame invFrame, UnconditionalValueDerefSet derefSet, boolean isEdge)
Check for unconditionally dereferenced null values at a particular location in the CFG.- Parameters:
thisLocation
-knownNullAndDoomedAt
-nullValueGuaranteedDerefMap
- map to be populated with null values and where they are derefedvnaFrame
- value number frame to checkinvFrame
- null-value frame to checkderefSet
- set of unconditionally derefed values at this locationisEdge
-
-
noteUnconditionallyDereferencedNullValue
private void noteUnconditionallyDereferencedNullValue(Location thisLocation, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugLocations, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, UnconditionalValueDerefSet derefSet, IsNullValue isNullValue, ValueNumber valueNumber)
Note the locations where a known-null value is unconditionally dereferenced.- Parameters:
thisLocation
-bugLocations
-nullValueGuaranteedDerefMap
- map of null values to sets of Locations where they are derefedderefSet
- set of values known to be unconditionally dereferencedisNullValue
- the null valuevalueNumber
- the value number of the null value
-
examineRedundantBranches
private void examineRedundantBranches()
Examine redundant branches.
-
analyzeRefComparisonBranch
private void analyzeRefComparisonBranch(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle lastHandle) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
analyzeIfNullBranch
private void analyzeIfNullBranch(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle lastHandle) throws DataflowAnalysisException
This is called for both IFNULL and IFNONNULL instructions.- Throws:
DataflowAnalysisException
-
analyzeNullCheck
private void analyzeNullCheck(IsNullValueDataflow invDataflow, BasicBlock basicBlock) throws DataflowAnalysisException, CFGBuilderException
-
findXFieldFromValueNumber
@Deprecated public static XField findXFieldFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
Deprecated.
-
findFieldAnnotationFromValueNumber
@Deprecated public static FieldAnnotation findFieldAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
-
findLocalAnnotationFromValueNumber
@Deprecated public static LocalVariableAnnotation findLocalAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
-
findAnnotationFromValueNumber
@Deprecated public static BugAnnotation findAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)
-
getLineNumber
private static int getLineNumber(org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle)
-
-