private void checkNonNullParam ( Location location , ConstantPoolGen cpg , TypeDataflow typeDataflow , InvokeInstruction invokeInstruction , BitSet nullArgSet , BitSet definitelyNullArgSet ) { if ( inExplicitCatchNullBlock ( location ) ) { return ; } boolean caught = inIndirectCatchNullBlock ( location ) ; if ( caught && skipIfInsideCatchNull ( ) ) { return ; } if ( invokeInstruction instanceof INVOKEDYNAMIC ) { return ; } XMethod m = XFactory . createXMethod ( invokeInstruction , cpg ) ; INullnessAnnotationDatabase db = AnalysisContext . currentAnalysisContext ( ) . getNullnessAnnotationDatabase ( ) ; SignatureParser sigParser = new SignatureParser ( invokeInstruction . getSignature ( cpg ) ) ; for ( int i = nullArgSet . nextSetBit ( 0 ) ; i >= 0 ; i = nullArgSet . nextSetBit ( i + 1 ) ) { if ( db . parameterMustBeNonNull ( m , i ) ) { boolean definitelyNull = definitelyNullArgSet . get ( i ) ; if ( DEBUG_NULLARG ) { System . out . println ( "Checking " + m ) ; System . out . println ( "QQQ2: " + i + " -- " + i + " is null" ) ; System . out . println ( "QQQ nullArgSet: " + nullArgSet ) ; System . out . println ( "QQQ dnullArgSet: " + definitelyNullArgSet ) ; } BugAnnotation variableAnnotation = null ; try { ValueNumberFrame vnaFrame = classContext . getValueNumberDataflow ( method ) . getFactAtLocation ( location ) ; ValueNumber valueNumber = vnaFrame . getArgument ( invokeInstruction , cpg , i , sigParser ) ; variableAnnotation = ValueNumberSourceInfo . findAnnotationFromValueNumber ( method , location , valueNumber , vnaFrame , "VALUE_OF" ) ; } catch ( DataflowAnalysisException e ) { AnalysisContext . logError ( "error" , e ) ; } catch ( CFGBuilderException e ) { AnalysisContext . logError ( "error" , e ) ; } int priority = definitelyNull ? HIGH_PRIORITY : NORMAL_PRIORITY ; if ( caught ) { priority ++ ; } if ( m . isPrivate ( ) && priority == HIGH_PRIORITY ) { priority = NORMAL_PRIORITY ; } String description = definitelyNull ? "INT_NULL_ARG" : "INT_MAYBE_NULL_ARG" ; WarningPropertySet < WarningProperty > propertySet = new WarningPropertySet <> ( ) ; Set < Location > derefLocationSet = Collections . singleton ( location ) ; addPropertiesForDereferenceLocations ( propertySet , derefLocationSet , false ) ; boolean duplicated = isDuplicated ( propertySet , location . getHandle ( ) . getPosition ( ) , false ) ; if ( duplicated ) { return ; } BugInstance warning = new BugInstance ( this , "NP_NONNULL_PARAM_VIOLATION" , priority ) . addClassAndMethod ( classContext . getJavaClass ( ) , method ) . addMethod ( m ) . describe ( MethodAnnotation . METHOD_CALLED ) . addParameterAnnotation ( i , description ) . addOptionalAnnotation ( variableAnnotation ) . addSourceLine ( classContext , method , location ) ; propertySet . decorateBugInstance ( warning ) ; bugReporter . reportBug ( warning ) ; } } }
We have a method invocation in which a possibly or definitely null parameter is passed . Check it against the library of nonnull annotations .