Class FindNullDeref

    • Field Detail

      • log

        private final org.slf4j.Logger log
      • DEBUG

        public static final boolean DEBUG
      • DEBUG_NULLARG

        private static final boolean DEBUG_NULLARG
      • DEBUG_NULLRETURN

        private static final boolean DEBUG_NULLRETURN
      • 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
      • checkedDatabases

        private boolean checkedDatabases
      • method

        private org.apache.bcel.classfile.Method method
      • previouslyDeadBlocks

        private java.util.BitSet previouslyDeadBlocks
      • catchTypesForNull

        @StaticConstant
        public static final java.util.Set<java.lang.String> catchTypesForNull
    • Constructor Detail

      • FindNullDeref

        public FindNullDeref​(BugReporter bugReporter)
    • Method Detail

      • 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
      • checkDatabases

        private void checkDatabases()
        Check whether the various interprocedural databases we can use exist and are nonempty.
      • getMethodNullnessAnnotation

        private NullnessAnnotation getMethodNullnessAnnotation()
        See if the currently-visited method declares a
      • checkCallSitesAndReturnInstructions

        private void checkCallSitesAndReturnInstructions()
      • hasManyPreceedingNullTests

        private boolean hasManyPreceedingNullTests​(int pc)
      • catchesNull

        public static boolean catchesNull​(org.apache.bcel.classfile.ConstantPool constantPool,
                                          org.apache.bcel.classfile.Code code,
                                          Location location)
      • safeCallToPrimateParseMethod

        private boolean safeCallToPrimateParseMethod​(XMethod calledMethod,
                                                     Location location)
      • checkUnconditionallyDereferencedParam

        private void checkUnconditionallyDereferencedParam​(Location location,
                                                           org.apache.bcel.generic.ConstantPoolGen cpg,
                                                           TypeDataflow typeDataflow,
                                                           org.apache.bcel.generic.InvokeInstruction invokeInstruction,
                                                           java.util.BitSet nullArgSet,
                                                           java.util.BitSet definitelyNullArgSet)
                                                    throws DataflowAnalysisException,
                                                           java.lang.ClassNotFoundException
        Throws:
        DataflowAnalysisException
        java.lang.ClassNotFoundException
      • checkNonNullParam

        private void checkNonNullParam​(Location location,
                                       org.apache.bcel.generic.ConstantPoolGen cpg,
                                       TypeDataflow typeDataflow,
                                       org.apache.bcel.generic.InvokeInstruction invokeInstruction,
                                       java.util.BitSet nullArgSet,
                                       java.util.BitSet definitelyNullArgSet)
        We have a method invocation in which a possibly or definitely null parameter is passed. Check it against the library of nonnull annotations.
        Parameters:
        location -
        cpg -
        typeDataflow -
        invokeInstruction -
        nullArgSet -
        definitelyNullArgSet -
      • 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

        private boolean skipIfInsideCatchNull()
      • 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
      • isThrower

        public static boolean isThrower​(BasicBlock target)
      • isGoto

        private boolean isGoto​(org.apache.bcel.generic.Instruction instruction)
        Determine whether the given instruction is a goto.
        Parameters:
        instruction - the instruction
        Returns:
        true if the instruction is a goto, false otherwise
      • minPC

        int minPC​(java.util.Collection<Location> locs)
      • maxPC

        int maxPC​(java.util.Collection<Location> locs)
      • callToAssertionMethod

        boolean callToAssertionMethod​(Location loc)
      • 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: 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
      • addPropertiesForDereferenceLocations

        private void addPropertiesForDereferenceLocations​(WarningPropertySet<WarningProperty> propertySet,
                                                          java.util.Collection<Location> derefLocationSet,
                                                          boolean isConsistent)
      • uniqueLocations

        private boolean uniqueLocations​(java.util.Collection<Location> derefLocationSet)
      • isDoomed

        private boolean isDoomed​(Location loc)
      • getDescription

        private java.lang.String getDescription​(Location loc,
                                                ValueNumber refValue)
      • inExplicitCatchNullBlock

        private boolean inExplicitCatchNullBlock​(Location loc)
      • inIndirectCatchNullBlock

        private boolean inIndirectCatchNullBlock​(Location loc)
      • isGeneratedCodeInCatchBlockViaLineNumber

        private static boolean isGeneratedCodeInCatchBlockViaLineNumber​(@NonNull
                                                                        org.apache.bcel.classfile.ConstantPool cp,
                                                                        @NonNull
                                                                        org.apache.bcel.classfile.LineNumberTable lineNumberTable,
                                                                        int line,
                                                                        @NonNull
                                                                        org.apache.bcel.generic.InstructionList instructions,
                                                                        @NonNull
                                                                        java.util.List<org.apache.bcel.classfile.CodeException> throwables)
        Java 11+ compiler generates redundant null checks for try-with-resources. This method tries to distinguish such code from manually written code by analysing null numbers.
        Parameters:
        cp - the constant pool
        lineNumberTable - the table with the line numbers
        line - the line which belongs to the program counter
        instructions - the list of instructions
        throwables - the list of Throwables in this method
        Returns:
        true if the pc specifies redundant null check generated by javac