Class FindNullDeref

java.lang.Object
edu.umd.cs.findbugs.detect.FindNullDeref
All Implemented Interfaces:
NullDerefAndRedundantComparisonCollector, Detector, Priorities, UseAnnotationDatabase

public class FindNullDeref 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.
Author:
David Hovemeyer, William Pugh
See Also:
  • Field Details

    • DEBUG

      public static final boolean DEBUG
    • catchTypesForNull

      @StaticConstant public static final Set<String> catchTypesForNull
  • Constructor Details

    • FindNullDeref

      public FindNullDeref(BugReporter bugReporter)
  • Method Details

    • visitClassContext

      public void visitClassContext(ClassContext classContext)
      Description copied from interface: Detector
      Visit the ClassContext for a class which should be analyzed for instances of bug patterns.
      Specified by:
      visitClassContext in interface Detector
      Parameters:
      classContext - the ClassContext
    • catchesNull

      public static boolean catchesNull(org.apache.bcel.classfile.ConstantPool constantPool, org.apache.bcel.classfile.Code code, Location location)
    • 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.
      Specified by:
      report in interface Detector
    • skipIfInsideCatchNull

      public boolean skipIfInsideCatchNull()
    • foundNullDeref

      public void foundNullDeref(Location location, ValueNumber valueNumber, IsNullValue refValue, ValueNumberFrame vnaFrame)
      Description copied from interface: NullDerefAndRedundantComparisonCollector
      Subclasses should override this method to capture locations where a null pointer is dereferenced.
      Specified by:
      foundNullDeref in interface NullDerefAndRedundantComparisonCollector
      Parameters:
      location - the Location of the null dereference
      valueNumber - the ValueNumber of the possibly-null value
      refValue - the kind of possibly-null value dereferenced
      vnaFrame - 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 interface NullDerefAndRedundantComparisonCollector
      Parameters:
      location - the Location of the null dereference
      valueNumber - the ValueNumber of the possibly-null value
      refValue - the kind of possibly-null value dereferenced
      vnaFrame - The ValueNumber Frame at the point where the dereference occurred
      isConsistent - true if the refValue is identical at all clones of the same instruction
    • isDuplicated

      public boolean isDuplicated(WarningPropertySet<WarningProperty> propertySet, int pc, boolean isConsistent)
    • isThrower

      public static boolean isThrower(BasicBlock target)
    • foundRedundantNullCheck

      public void foundRedundantNullCheck(Location location, RedundantBranch redundantBranch)
      Description copied from interface: NullDerefAndRedundantComparisonCollector
      Subclasses should override this method to capture locations where a redundant null comparison is performed.
      Specified by:
      foundRedundantNullCheck in interface NullDerefAndRedundantComparisonCollector
      Parameters:
      location - the Location of the redundant null check
      redundantBranch - 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 interface NullDerefAndRedundantComparisonCollector
      Parameters:
      assignedNullLocationSet - set of locations where the value becomes null
      derefLocationSet - set of locations where dereferences occur
      doomedLocations - locations at which the value is doomed
      vna - ValueNumberDataflow
      refValue - the null value
      variableAnnotation - TODO
      deref - TODO
      npeIfStatementCovered - true if doom location is a statement