Class NullnessTransfer
- All Implemented Interfaces:
ForwardTransferFunction<NullnessValue,,NullnessStore> TransferFunction<NullnessValue,,NullnessStore> NodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>>
- After an expression is compared with the
nullliteral, then that expression can safely be consideredNonNullif the result of the comparison is false orNullableif the result is true. - If an expression is dereferenced, then it can safely be assumed to non-null in the future.
If it would not be, then the dereference would have raised a
NullPointerException. - Tracks whether
PolyNullis known to beNonNullorNullable(or not known to be either).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @Nullable KeyForAnnotatedTypeFactoryThe type factory for the map key analysis, or null if the Map Key Checker should not be run.protected final AnnotatedTypeMirror.AnnotatedDeclaredTypeJava's Map interface.protected final AnnotationMirrorThe @NonNullannotation.protected final AnnotationMirrorThe @Nullableannotation.protected final NullnessAnnotatedTypeFactoryThe type factory for the nullness analysis that was passed to the constructor.protected final AnnotationMirrorThe @PolyNullannotation.Fields inherited from class org.checkerframework.checker.initialization.InitializationTransfer
atypeFactoryFields inherited from class org.checkerframework.framework.flow.CFAbstractTransfer
analysis, sequentialSemantics -
Constructor Summary
ConstructorsConstructorDescriptionNullnessTransfer(NullnessAnalysis analysis) Create a new NullnessTransfer for the given analysis. -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable NullnessValuefinishValue(@Nullable NullnessValue value, NullnessStore store) A hook for subclasses to modify the result of the transfer function.protected @Nullable NullnessValuefinishValue(@Nullable NullnessValue value, NullnessStore thenStore, NullnessStore elseStore) A hook for subclasses to modify the result of the transfer function.protected voidmakeNonNull(NullnessStore store, Node node) Sets a givenNodeto non-null in the givenstore.protected voidmakeNonNull(TransferResult<NullnessValue, NullnessStore> result, Node node) protected voidRefine the given result to @NonNull.protected TransferResult<NullnessValue, NullnessStore> strengthenAnnotationOfEqualTo(TransferResult<NullnessValue, NullnessStore> res, Node firstNode, Node secondNode, NullnessValue firstValue, NullnessValue secondValue, boolean notEqualTo) Refine the annotation ofsecondNodeif the annotationsecondValueis less precise thanfirstValue.If an invariant field is initialized and has the invariant annotation, then it has at least the invariant annotation.Methods inherited from class org.checkerframework.checker.initialization.InitializationTransfer
initializedFieldsAfterCall, isNotFullyInitializedReceiver, markInvariantFieldsAsInitialized, visitAssignmentMethods inherited from class org.checkerframework.framework.flow.CFAbstractTransfer
addInformationFromPreconditions, createTransferResult, createTransferResult, getNarrowedValue, getValueFromFactory, getWidenedValue, initialStore, insertIntoStores, insertIntoStoresPermitNonDeterministic, moreSpecificValue, processCommonAssignment, processConditionalPostconditions, processPostconditions, recreateTransferResult, recreateTransferResult, setFixedInitialStore, shouldPerformWholeProgramInference, shouldPerformWholeProgramInference, splitAssignments, usesSequentialSemantics, visitAnyPattern, visitCase, visitClassName, visitConditionalNot, visitDeconstructorPattern, visitEqualTo, visitExpressionStatement, visitLambdaResultExpression, visitLocalVariable, visitNarrowingConversion, visitNode, visitNotEqual, visitObjectCreation, visitStringConversion, visitSwitchExpressionNode, visitTernaryExpression, visitThis, visitVariableDeclaration, visitWideningConversionMethods inherited from class org.checkerframework.dataflow.cfg.node.AbstractNodeVisitor
visitArrayCreation, visitArrayType, visitAssertionError, visitBitwiseAnd, visitBitwiseComplement, visitBitwiseOr, visitBitwiseXor, visitBooleanLiteral, visitCharacterLiteral, visitClassDeclaration, visitConditionalAnd, visitConditionalOr, visitDoubleLiteral, visitExplicitThis, visitFloatingDivision, visitFloatingRemainder, visitFloatLiteral, visitGreaterThan, visitGreaterThanOrEqual, visitImplicitThis, visitIntegerDivision, visitIntegerLiteral, visitIntegerRemainder, visitLeftShift, visitLessThan, visitLessThanOrEqual, visitLongLiteral, visitMarker, visitMemberReference, visitNullChk, visitNullLiteral, visitNumericalAddition, visitNumericalMinus, visitNumericalMultiplication, visitNumericalPlus, visitNumericalSubtraction, visitPackageName, visitParameterizedType, visitPrimitiveType, visitShortLiteral, visitSignedRightShift, visitStringConcatenate, visitStringLiteral, visitSuper, visitSynchronized, visitTypeCast, visitUnsignedRightShift, visitValueLiteralMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.checkerframework.dataflow.cfg.node.NodeVisitor
visitArrayCreation, visitArrayType, visitAssertionError, visitBitwiseAnd, visitBitwiseComplement, visitBitwiseOr, visitBitwiseXor, visitBooleanLiteral, visitCharacterLiteral, visitClassDeclaration, visitConditionalAnd, visitConditionalOr, visitDoubleLiteral, visitExplicitThis, visitFloatingDivision, visitFloatingRemainder, visitFloatLiteral, visitGreaterThan, visitGreaterThanOrEqual, visitImplicitThis, visitIntegerDivision, visitIntegerLiteral, visitIntegerRemainder, visitLeftShift, visitLessThan, visitLessThanOrEqual, visitLongLiteral, visitMarker, visitMemberReference, visitNullChk, visitNullLiteral, visitNumericalAddition, visitNumericalMinus, visitNumericalMultiplication, visitNumericalPlus, visitNumericalSubtraction, visitPackageName, visitParameterizedType, visitPrimitiveType, visitShortLiteral, visitSignedRightShift, visitStringConcatenate, visitStringLiteral, visitSuper, visitSynchronized, visitTypeCast, visitUnsignedRightShift
-
Field Details
-
NONNULL
The @NonNullannotation. -
NULLABLE
The @Nullableannotation. -
POLYNULL
The @PolyNullannotation. -
MAP_TYPE
Java's Map interface.The qualifiers in this type don't matter -- it is not used as a fully-annotated AnnotatedDeclaredType, but just passed to asSuper().
-
nullnessTypeFactory
The type factory for the nullness analysis that was passed to the constructor. -
keyForTypeFactory
The type factory for the map key analysis, or null if the Map Key Checker should not be run.
-
-
Constructor Details
-
NullnessTransfer
Create a new NullnessTransfer for the given analysis.- Parameters:
analysis- nullness analysis
-
-
Method Details
-
makeNonNull
Sets a givenNodeto non-null in the givenstore. Calls to this method implement case 2.- Parameters:
store- the store to updatenode- the node that should be non-null
-
makeNonNull
-
refineToNonNull
Refine the given result to @NonNull. -
finishValue
Description copied from class:CFAbstractTransferA hook for subclasses to modify the result of the transfer function. This method is called before returning the abstract valuevalueas the result of the transfer function.If a subclass overrides this method, the subclass should also override
CFAbstractTransfer.finishValue(CFAbstractValue,CFAbstractStore,CFAbstractStore).- Overrides:
finishValuein classCFAbstractTransfer<NullnessValue,NullnessStore, NullnessTransfer> - Parameters:
value- a value to possibly modifystore- the store- Returns:
- the possibly-modified value
-
finishValue
protected @Nullable NullnessValue finishValue(@Nullable NullnessValue value, NullnessStore thenStore, NullnessStore elseStore) Description copied from class:CFAbstractTransferA hook for subclasses to modify the result of the transfer function. This method is called before returning the abstract valuevalueas the result of the transfer function.If a subclass overrides this method, the subclass should also override
CFAbstractTransfer.finishValue(CFAbstractValue,CFAbstractStore).- Overrides:
finishValuein classCFAbstractTransfer<NullnessValue,NullnessStore, NullnessTransfer> - Parameters:
value- the value to finishthenStore- the "then" storeelseStore- the "else" store- Returns:
- the possibly-modified value
-
strengthenAnnotationOfEqualTo
protected TransferResult<NullnessValue,NullnessStore> strengthenAnnotationOfEqualTo(TransferResult<NullnessValue, NullnessStore> res, Node firstNode, Node secondNode, NullnessValue firstValue, NullnessValue secondValue, boolean notEqualTo) Refine the annotation ofsecondNodeif the annotationsecondValueis less precise thanfirstValue. This is possible, ifsecondNodeis an expression that is tracked by the store (e.g., a local variable or a field). Clients usually call this twice withfirstNodeandsecondNodereversed, to refine each of them.Note that when overriding this method, when a new type is inserted into the store,
CFAbstractTransfer.splitAssignments(org.checkerframework.dataflow.cfg.node.Node)should be called, and the new type should be inserted into the store for each of the resulting nodes.Furthermore, this method refines the type to
NonNullfor the appropriate branch if an expression is compared to thenullliteral (listed as case 1 in the class description).- Overrides:
strengthenAnnotationOfEqualToin classCFAbstractTransfer<NullnessValue,NullnessStore, NullnessTransfer> - Parameters:
res- the previous resultfirstNode- the node that might be more precisesecondNode- the node whose type to possibly refinefirstValue- the abstract value that might be more precisesecondValue- the abstract value that might be less precisenotEqualTo- if true, indicates that the logic is flipped (i.e., the information is added to theelseStoreinstead of thethenStore) for a not-equal comparison- Returns:
- the conditional transfer result (if information has been added), or
res
-
visitArrayAccess
public TransferResult<NullnessValue,NullnessStore> visitArrayAccess(ArrayAccessNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitArrayAccessin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitArrayAccessin classCFAbstractTransfer<NullnessValue,NullnessStore, NullnessTransfer>
-
visitInstanceOf
public TransferResult<NullnessValue,NullnessStore> visitInstanceOf(InstanceOfNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitInstanceOfin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitInstanceOfin classCFAbstractTransfer<NullnessValue,NullnessStore, NullnessTransfer>
-
visitMethodAccess
public TransferResult<NullnessValue,NullnessStore> visitMethodAccess(MethodAccessNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitMethodAccessin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitMethodAccessin classAbstractNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>>
-
visitFieldAccess
public TransferResult<NullnessValue,NullnessStore> visitFieldAccess(FieldAccessNode n, TransferInput<NullnessValue, NullnessStore> p) Description copied from class:InitializationTransferIf an invariant field is initialized and has the invariant annotation, then it has at least the invariant annotation. Note that only fields of the 'this' receiver are tracked for initialization.- Specified by:
visitFieldAccessin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitFieldAccessin classInitializationTransfer<NullnessValue,NullnessTransfer, NullnessStore>
-
visitThrow
public TransferResult<NullnessValue,NullnessStore> visitThrow(ThrowNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitThrowin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitThrowin classAbstractNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>>
-
visitMethodInvocation
public TransferResult<NullnessValue,NullnessStore> visitMethodInvocation(MethodInvocationNode n, TransferInput<NullnessValue, NullnessStore> in) When the invocationPreservesArgumentNullness flag is turned on, the receiver and arguments that are passed to non-null parameters in a method call or constructor invocation are unsoundly assumed to be non-null after the invocation.
When the flag is turned off, the analysis is sound: it checks that the method is SideEffectFree or the receiver is unassignable. Only if either one of the two is true, is the receiver made non-null. Similar logic is applied to the arguments of the invocation.
Provided that m is of a type that implements interface java.util.Map:
- Given a call m.get(k), if k is @KeyFor("m") and m's value type is @NonNull, then the result is @NonNull in the thenStore and elseStore of the transfer result.
- Specified by:
visitMethodInvocationin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitMethodInvocationin classInitializationTransfer<NullnessValue,NullnessTransfer, NullnessStore>
-
visitReturn
public TransferResult<NullnessValue,NullnessStore> visitReturn(ReturnNode n, TransferInput<NullnessValue, NullnessStore> in) - Specified by:
visitReturnin interfaceNodeVisitor<TransferResult<NullnessValue,NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitReturnin classCFAbstractTransfer<NullnessValue,NullnessStore, NullnessTransfer>
-