Package edu.umd.cs.findbugs.detect
Class NoiseNullDeref
java.lang.Object
edu.umd.cs.findbugs.detect.NoiseNullDeref
- All Implemented Interfaces:
NullDerefAndRedundantComparisonCollector
,Detector
,Priorities
,UseAnnotationDatabase
public class NoiseNullDeref
extends Object
implements Detector, UseAnnotationDatabase, NullDerefAndRedundantComparisonCollector
A Detector to find instructions where a NullPointerException might be raised.
We also look for useless reference comparisons involving null and non-null
values.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BugAccumulator
private final BugReporter
private static final String
private ClassContext
static final boolean
private static final boolean
private static final boolean
private org.apache.bcel.classfile.Method
private static final String
private ValueNumberDataflow
Fields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addPropertiesForDereferenceLocations
(WarningPropertySet<WarningProperty> propertySet, Collection<Location> derefLocationSet) private void
private void
analyzeMethod
(ClassContext classContext, org.apache.bcel.classfile.Method method) private BitSet
Find set of blocks which were known to be dead before doing the null pointer analysis.void
foundGuaranteedNullDeref
(Set<Location> assignedNullLocationSet, Set<Location> derefLocationSet, SortedSet<Location> doomedLocations, ValueNumberDataflow vna, ValueNumber refValue, BugAnnotation variableAnnotation, NullValueUnconditionalDeref deref, boolean npeIfStatementCovered) Subclasses should override this method to capture values assigned null (or that become null through a comparison and branch) that are guaranteed to reach a dereference (ignoring implicit exception paths).void
foundNullDeref
(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame) Deprecated.void
foundNullDeref
(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame, boolean isConsistent) Subclasses should override this method to capture locations where a null pointer is dereferenced.void
foundRedundantNullCheck
(Location location, RedundantBranch redundantBranch) Subclasses should override this method to capture locations where a redundant null comparison is performed.(package private) String
getDescription
(Location loc, ValueNumber refValue) (package private) boolean
inCatchNullBlock
(Location loc) private boolean
static boolean
isThrower
(BasicBlock target) void
report()
This method is called after all classes to be visited.private void
reportNullDeref
(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority, BugAnnotation cause, BugAnnotation variable) boolean
private boolean
uniqueLocations
(Collection<Location> derefLocationSet) void
visitClassContext
(ClassContext classContext) Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
-
Field Details
-
DEBUG
public static final boolean DEBUG -
DEBUG_NULLARG
private static final boolean DEBUG_NULLARG -
MARK_DOOMED
private static final boolean MARK_DOOMED -
METHOD_NAME
-
CLASS
-
bugReporter
-
bugAccumulator
-
classContext
-
method
private org.apache.bcel.classfile.Method method -
vnaDataflow
-
-
Constructor Details
-
NoiseNullDeref
-
-
Method Details
-
visitClassContext
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 -
findPreviouslyDeadBlocks
Find set of blocks which were known to be dead before doing the null pointer analysis.- Returns:
- set of previously dead blocks, indexed by block id
- Throws:
CFGBuilderException
DataflowAnalysisException
-
report
public void report()Description copied from interface:Detector
This method is called after all classes to be visited. It should be used by any detectors which accumulate information over all visited classes to generate results. -
skipIfInsideCatchNull
public boolean skipIfInsideCatchNull() -
foundNullDeref
@Deprecated public void foundNullDeref(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame) Deprecated.Description copied from interface:NullDerefAndRedundantComparisonCollector
Subclasses should override this method to capture locations where a null pointer is dereferenced.- Specified by:
foundNullDeref
in interfaceNullDerefAndRedundantComparisonCollector
- Parameters:
location
- the Location of the null dereferencevalueNumber
- the ValueNumber of the possibly-null valuerefValue
- the kind of possibly-null value dereferencedvnaFrame
- The ValueNumber Frame at the point where the dereference occurred
-
foundNullDeref
public void foundNullDeref(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame, boolean isConsistent) Description copied from interface:NullDerefAndRedundantComparisonCollector
Subclasses should override this method to capture locations where a null pointer is dereferenced.- Specified by:
foundNullDeref
in interfaceNullDerefAndRedundantComparisonCollector
- Parameters:
location
- the Location of the null dereferencevalueNumber
- the ValueNumber of the possibly-null valuerefValue
- the kind of possibly-null value dereferencedvnaFrame
- The ValueNumber Frame at the point where the dereference occurredisConsistent
- true if the refValue is identical at all clones of the same instruction
-
reportNullDeref
private void reportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority, BugAnnotation cause, @CheckForNull BugAnnotation variable) -
isThrower
-
foundRedundantNullCheck
Description copied from interface:NullDerefAndRedundantComparisonCollector
Subclasses should override this method to capture locations where a redundant null comparison is performed.- Specified by:
foundRedundantNullCheck
in interfaceNullDerefAndRedundantComparisonCollector
- Parameters:
location
- the Location of the redundant null checkredundantBranch
- the RedundantBranch
-
foundGuaranteedNullDeref
public void foundGuaranteedNullDeref(@Nonnull Set<Location> assignedNullLocationSet, @Nonnull Set<Location> derefLocationSet, SortedSet<Location> doomedLocations, ValueNumberDataflow vna, ValueNumber refValue, @CheckForNull BugAnnotation variableAnnotation, NullValueUnconditionalDeref deref, boolean npeIfStatementCovered) Description copied from interface:NullDerefAndRedundantComparisonCollector
Subclasses should override this method to capture values assigned null (or that become null through a comparison and branch) that are guaranteed to reach a dereference (ignoring implicit exception paths).- Specified by:
foundGuaranteedNullDeref
in interfaceNullDerefAndRedundantComparisonCollector
- Parameters:
assignedNullLocationSet
- set of locations where the value becomes nullderefLocationSet
- set of locations where dereferences occurdoomedLocations
- locations at which the value is doomedvna
- ValueNumberDataflowrefValue
- the null valuevariableAnnotation
- TODOderef
- TODOnpeIfStatementCovered
- true if doom location is a statement
-
addPropertiesForDereferenceLocations
private void addPropertiesForDereferenceLocations(WarningPropertySet<WarningProperty> propertySet, Collection<Location> derefLocationSet) -
uniqueLocations
-
addPropertiesForMethodContainingWarning
private void addPropertiesForMethodContainingWarning(WarningPropertySet<WarningProperty> propertySet) -
isDoomed
-
getDescription
-
inCatchNullBlock
-
foundNullDeref(Location,ValueNumber,IsNullValue,ValueNumberFrame,boolean)
instead