Class NullDerefAndRedundantComparisonFinder
java.lang.Object
edu.umd.cs.findbugs.ba.npe.NullDerefAndRedundantComparisonFinder
A user-friendly front end for finding null pointer dereferences and redundant
null comparisons.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AssertionMethodsprivate final ClassContextprivate final NullDerefAndRedundantComparisonCollectorprivate static final booleanprivate static final booleanprivate final BitSetprivate final BitSetprivate final booleanprivate IsNullValueDataflowprivate final BitSetprivate final org.apache.bcel.classfile.Methodprivate static final booleanprivate static final booleanprivate final List<RedundantBranch> private final BitSetprivate UnconditionalValueDerefDataflowprivate ValueNumberDataflow -
Constructor Summary
ConstructorsConstructorDescriptionNullDerefAndRedundantComparisonFinder(ClassContext classContext, org.apache.bcel.classfile.Method method, NullDerefAndRedundantComparisonCollector collector) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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, Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, Map<ValueNumber, SortedSet<Location>> bugEdgeLocationMap) private voidcheckForUnconditionallyDereferencedNullValues(Location thisLocation, Map<ValueNumber, SortedSet<Location>> knownNullAndDoomedAt, 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 voidExamine basic blocks for null checks and potentially-redundant null comparisons.private voidExamine null values.private voidExamine redundant branches.voidexecute()static BugAnnotationfindAnnotationFromValueNumber(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame) Deprecated.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) findNullAssignments(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, Map<ValueNumber, SortedSet<Location>> bugLocations, Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, UnconditionalValueDerefSet derefSet, IsNullValue isNullValue, ValueNumber valueNumber) Note the locations where a known-null value is unconditionally dereferenced.private voidremoveStrictlyDominatedLocations(Set<Location> locations, DominatorsAnalysis domAnalysis) private voidremoveStrictlyPostDominatedLocations(Set<Location> locations, PostDominatorsAnalysis postDomAnalysis) voidreportBugs(Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, HashSet<ValueNumber> npeIfStatementCovered, Map<ValueNumber, SortedSet<Location>> bugLocationMap, Map<ValueNumber, Set<Location>> nullValueAssignmentMap)
-
Field Details
-
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
-
method
private final org.apache.bcel.classfile.Method method -
collector
-
findGuaranteedDerefs
private final boolean findGuaranteedDerefs -
redundantBranchList
-
definitelySameBranchSet
-
definitelyDifferentBranchSet
-
undeterminedBranchSet
-
lineMentionedMultipleTimes
-
invDataflow
-
vnaDataflow
-
uvdDataflow
-
assertionMethods
-
MY_DEBUG
private static final boolean MY_DEBUG- See Also:
-
-
Constructor Details
-
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 Details
-
execute
public void execute() -
examineBasicBlocks
Examine basic blocks for null checks and potentially-redundant null comparisons. -
examineNullValues
Examine null values. Report any that are guaranteed to be dereferenced on non-implicit-exception paths. -
findNullAssignments
public Map<ValueNumber, Set<Location>> findNullAssignments(Set<LocationWhereValueBecomesNull> locationWhereValueBecomesNullSet) -
reportBugs
public void reportBugs(Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, HashSet<ValueNumber> npeIfStatementCovered, Map<ValueNumber, SortedSet<Location>> bugLocationMap, Map<ValueNumber, Set<Location>> nullValueAssignmentMap) throws CFGBuilderException, DataflowAnalysisException -
checkEdges
public void checkEdges(CFG cfg, Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, Map<ValueNumber, SortedSet<Location>> bugEdgeLocationMap) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
removeStrictlyPostDominatedLocations
private void removeStrictlyPostDominatedLocations(Set<Location> locations, PostDominatorsAnalysis postDomAnalysis) -
removeStrictlyDominatedLocations
private void removeStrictlyDominatedLocations(Set<Location> locations, DominatorsAnalysis domAnalysis) -
checkForUnconditionallyDereferencedNullValues
private void checkForUnconditionallyDereferencedNullValues(Location thisLocation, Map<ValueNumber, SortedSet<Location>> knownNullAndDoomedAt, 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, Map<ValueNumber, SortedSet<Location>> bugLocations, 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)
-
ValueNumberSourceInfo.findRequiredAnnotationFromValueNumber(Method,Location,ValueNumber,ValueNumberFrame, String)instead