Package edu.umd.cs.findbugs.ba.npe
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 AssertionMethods
private final ClassContext
private final NullDerefAndRedundantComparisonCollector
private static final boolean
private static final boolean
private final BitSet
private final BitSet
private final boolean
private IsNullValueDataflow
private final BitSet
private final org.apache.bcel.classfile.Method
private static final boolean
private static final boolean
private final List
<RedundantBranch> private final BitSet
private UnconditionalValueDerefDataflow
private ValueNumberDataflow
-
Constructor Summary
ConstructorsConstructorDescriptionNullDerefAndRedundantComparisonFinder
(ClassContext classContext, org.apache.bcel.classfile.Method method, NullDerefAndRedundantComparisonCollector collector) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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, Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, Map<ValueNumber, SortedSet<Location>> bugEdgeLocationMap) 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.private void
Examine basic blocks for null checks and potentially-redundant null comparisons.private void
Examine null values.private void
Examine redundant branches.void
execute()
static BugAnnotation
findAnnotationFromValueNumber
(org.apache.bcel.classfile.Method method, Location location, ValueNumber valueNumber, ValueNumberFrame vnaFrame) Deprecated.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) findNullAssignments
(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, 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 void
removeStrictlyDominatedLocations
(Set<Location> locations, DominatorsAnalysis domAnalysis) private void
removeStrictlyPostDominatedLocations
(Set<Location> locations, PostDominatorsAnalysis postDomAnalysis) void
reportBugs
(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, throws CFGBuilderException, DataflowAnalysisExceptionSortedSet<Location>> bugLocationMap, Map<ValueNumber, Set<Location>> nullValueAssignmentMap) -
checkEdges
public void checkEdges(CFG cfg, Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, Map<ValueNumber, throws DataflowAnalysisExceptionSortedSet<Location>> bugEdgeLocationMap) - 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