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.ObjectA 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 AssertionMethodsassertionMethodsprivate ClassContextclassContextprivate NullDerefAndRedundantComparisonCollectorcollectorprivate static booleanDEBUGprivate static booleanDEBUG_DEREFSprivate java.util.BitSetdefinitelyDifferentBranchSetprivate java.util.BitSetdefinitelySameBranchSetprivate booleanfindGuaranteedDerefsprivate IsNullValueDataflowinvDataflowprivate java.util.BitSetlineMentionedMultipleTimesprivate org.apache.bcel.classfile.Methodmethodprivate static booleanMY_DEBUGprivate static booleanPRUNE_GUARANTEED_DEREFERENCESprivate java.util.List<RedundantBranch>redundantBranchListprivate java.util.BitSetundeterminedBranchSetprivate UnconditionalValueDerefDataflowuvdDataflowprivate ValueNumberDataflowvnaDataflow
-
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 voidanalyzeIfNullBranch(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle lastHandle)This is called for both IFNULL and IFNONNULL instructions.private voidanalyzeNullCheck(IsNullValueDataflow invDataflow, BasicBlock basicBlock)private voidanalyzeRefComparisonBranch(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle lastHandle)voidcheckEdges(CFG cfg, java.util.Map<ValueNumber,NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, java.util.Map<ValueNumber,java.util.SortedSet<Location>> bugEdgeLocationMap)private voidcheckForUnconditionallyDereferencedNullValues(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 voidexamineBasicBlocks()Examine basic blocks for null checks and potentially-redundant null comparisons.private voidexamineNullValues()Examine null values.private voidexamineRedundantBranches()Examine redundant branches.voidexecute()static BugAnnotationfindAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)static FieldAnnotationfindFieldAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)static LocalVariableAnnotationfindLocalAnnotationFromValueNumber(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 XFieldfindXFieldFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame)Deprecated.private static intgetLineNumber(org.apache.bcel.classfile.Method method, org.apache.bcel.generic.InstructionHandle handle)private voidnoteUnconditionallyDereferencedNullValue(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 voidremoveStrictlyDominatedLocations(java.util.Set<Location> locations, DominatorsAnalysis domAnalysis)private voidremoveStrictlyPostDominatedLocations(java.util.Set<Location> locations, PostDominatorsAnalysis postDomAnalysis)voidreportBugs(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, CFGBuilderExceptionExamine basic blocks for null checks and potentially-redundant null comparisons.
-
examineNullValues
private void examineNullValues() throws CFGBuilderException, DataflowAnalysisExceptionExamine 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)
-
-