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 java.lang.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:
IsNullValueAnalysis
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classNoiseNullDeref.CheckCallSitesAndReturnInstructions
-
Field Summary
Fields Modifier and Type Field Description private BugAccumulatorbugAccumulatorprivate BugReporterbugReporterprivate static java.lang.StringCLASSprivate ClassContextclassContextstatic booleanDEBUGprivate static booleanDEBUG_NULLARGprivate static booleanMARK_DOOMEDprivate org.apache.bcel.classfile.Methodmethodprivate static java.lang.StringMETHOD_NAMEprivate ValueNumberDataflowvnaDataflow-
Fields inherited from interface edu.umd.cs.findbugs.Priorities
EXP_PRIORITY, HIGH_PRIORITY, IGNORE_PRIORITY, LOW_PRIORITY, NORMAL_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description NoiseNullDeref(BugReporter bugReporter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private voidaddPropertiesForDereferenceLocations(WarningPropertySet<WarningProperty> propertySet, java.util.Collection<Location> derefLocationSet)private voidaddPropertiesForMethodContainingWarning(WarningPropertySet<WarningProperty> propertySet)private voidanalyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method)private java.util.BitSetfindPreviouslyDeadBlocks()Find set of blocks which were known to be dead before doing the null pointer analysis.voidfoundGuaranteedNullDeref(java.util.Set<Location> assignedNullLocationSet, java.util.Set<Location> derefLocationSet, java.util.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).voidfoundNullDeref(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame)Deprecated.voidfoundNullDeref(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame, boolean isConsistent)Subclasses should override this method to capture locations where a null pointer is dereferenced.voidfoundRedundantNullCheck(Location location, RedundantBranch redundantBranch)Subclasses should override this method to capture locations where a redundant null comparison is performed.(package private) java.lang.StringgetDescription(Location loc, ValueNumber refValue)(package private) booleaninCatchNullBlock(Location loc)private booleanisDoomed(Location loc)static booleanisThrower(BasicBlock target)voidreport()This method is called after all classes to be visited.private voidreportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, java.lang.String type, int priority, BugAnnotation cause, BugAnnotation variable)booleanskipIfInsideCatchNull()private booleanuniqueLocations(java.util.Collection<Location> derefLocationSet)voidvisitClassContext(ClassContext classContext)Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
-
DEBUG_NULLARG
private static final boolean DEBUG_NULLARG
-
MARK_DOOMED
private static final boolean MARK_DOOMED
-
METHOD_NAME
private static final java.lang.String METHOD_NAME
-
CLASS
private static final java.lang.String CLASS
-
bugReporter
private final BugReporter bugReporter
-
bugAccumulator
private final BugAccumulator bugAccumulator
-
classContext
private ClassContext classContext
-
method
private org.apache.bcel.classfile.Method method
-
vnaDataflow
private ValueNumberDataflow vnaDataflow
-
-
Constructor Detail
-
NoiseNullDeref
public NoiseNullDeref(BugReporter bugReporter)
-
-
Method Detail
-
visitClassContext
public void visitClassContext(ClassContext classContext)
Description copied from interface:DetectorVisit the ClassContext for a class which should be analyzed for instances of bug patterns.- Specified by:
visitClassContextin interfaceDetector- Parameters:
classContext- the ClassContext
-
analyzeMethod
private void analyzeMethod(ClassContext classContext, org.apache.bcel.classfile.Method method) throws DataflowAnalysisException, CFGBuilderException
-
findPreviouslyDeadBlocks
private java.util.BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderExceptionFind 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:
CFGBuilderExceptionDataflowAnalysisException
-
report
public void report()
Description copied from interface:DetectorThis 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:NullDerefAndRedundantComparisonCollectorSubclasses should override this method to capture locations where a null pointer is dereferenced.- Specified by:
foundNullDerefin 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:NullDerefAndRedundantComparisonCollectorSubclasses should override this method to capture locations where a null pointer is dereferenced.- Specified by:
foundNullDerefin 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, java.lang.String type, int priority, BugAnnotation cause, @CheckForNull BugAnnotation variable)
-
isThrower
public static boolean isThrower(BasicBlock target)
-
foundRedundantNullCheck
public void foundRedundantNullCheck(Location location, RedundantBranch redundantBranch)
Description copied from interface:NullDerefAndRedundantComparisonCollectorSubclasses should override this method to capture locations where a redundant null comparison is performed.- Specified by:
foundRedundantNullCheckin interfaceNullDerefAndRedundantComparisonCollector- Parameters:
location- the Location of the redundant null checkredundantBranch- the RedundantBranch
-
foundGuaranteedNullDeref
public void foundGuaranteedNullDeref(@Nonnull java.util.Set<Location> assignedNullLocationSet, @Nonnull java.util.Set<Location> derefLocationSet, java.util.SortedSet<Location> doomedLocations, ValueNumberDataflow vna, ValueNumber refValue, @CheckForNull BugAnnotation variableAnnotation, NullValueUnconditionalDeref deref, boolean npeIfStatementCovered)Description copied from interface:NullDerefAndRedundantComparisonCollectorSubclasses 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:
foundGuaranteedNullDerefin 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, java.util.Collection<Location> derefLocationSet)
-
uniqueLocations
private boolean uniqueLocations(java.util.Collection<Location> derefLocationSet)
-
addPropertiesForMethodContainingWarning
private void addPropertiesForMethodContainingWarning(WarningPropertySet<WarningProperty> propertySet)
-
isDoomed
private boolean isDoomed(Location loc)
-
getDescription
java.lang.String getDescription(Location loc, ValueNumber refValue)
-
inCatchNullBlock
boolean inCatchNullBlock(Location loc)
-
-