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
null
literal, then that expression can safely be consideredNonNull
if the result of the comparison is false orNullable
if 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
PolyNull
is known to beNonNull
orNullable
(or not known to be either).
-
Field Summary
Modifier and TypeFieldDescriptionprotected final @Nullable KeyForAnnotatedTypeFactory
The type factory for the map key analysis, or null if the Map Key Checker should not be run.protected final AnnotatedTypeMirror.AnnotatedDeclaredType
Java's Map interface.protected final AnnotationMirror
The @NonNull
annotation.protected final AnnotationMirror
The @Nullable
annotation.protected final NullnessAnnotatedTypeFactory
The type factory for the nullness analysis that was passed to the constructor.protected final AnnotationMirror
The @PolyNull
annotation.Fields inherited from class org.checkerframework.checker.initialization.InitializationTransfer
atypeFactory
Fields inherited from class org.checkerframework.framework.flow.CFAbstractTransfer
analysis, sequentialSemantics
-
Constructor Summary
ConstructorDescriptionNullnessTransfer
(NullnessAnalysis analysis) Create a new NullnessTransfer for the given analysis. -
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable NullnessValue
finishValue
(@Nullable NullnessValue value, NullnessStore store) A hook for subclasses to modify the result of the transfer function.protected @Nullable NullnessValue
finishValue
(@Nullable NullnessValue value, NullnessStore thenStore, NullnessStore elseStore) A hook for subclasses to modify the result of the transfer function.protected void
makeNonNull
(NullnessStore store, Node node) Sets a givenNode
to non-null in the givenstore
.protected void
makeNonNull
(TransferResult<NullnessValue, NullnessStore> result, Node node) protected void
Refine 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 ofsecondNode
if the annotationsecondValue
is less precise thanfirstValue
.If an invariant field is initialized and has the invariant annotation, than it has at least the invariant annotation.Methods inherited from class org.checkerframework.checker.initialization.InitializationTransfer
initializedFieldsAfterCall, isNotFullyInitializedReceiver, markInvariantFieldsAsInitialized, visitAssignment
Methods inherited from class org.checkerframework.framework.flow.CFAbstractTransfer
addInformationFromPreconditions, createTransferResult, getNarrowedValue, getValueFromFactory, getWidenedValue, initialStore, insertIntoStores, moreSpecificValue, processCommonAssignment, processConditionalPostconditions, processPostconditions, recreateTransferResult, setFixedInitialStore, splitAssignments, usesSequentialSemantics, visitCase, visitClassName, visitConditionalNot, visitEqualTo, visitExpressionStatement, visitLambdaResultExpression, visitLocalVariable, visitNarrowingConversion, visitNode, visitNotEqual, visitObjectCreation, visitStringConversion, visitSwitchExpressionNode, visitTernaryExpression, visitThis, visitVariableDeclaration, visitWideningConversion
Methods 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, visitValueLiteral
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 @NonNull
annotation. -
NULLABLE
The @Nullable
annotation. -
POLYNULL
The @PolyNull
annotation. -
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 givenNode
to 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:CFAbstractTransfer
A hook for subclasses to modify the result of the transfer function. This method is called before returning the abstract valuevalue
as the result of the transfer function.If a subclass overrides this method, the subclass should also override
CFAbstractTransfer.finishValue(CFAbstractValue,CFAbstractStore,CFAbstractStore)
.- Overrides:
finishValue
in 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:CFAbstractTransfer
A hook for subclasses to modify the result of the transfer function. This method is called before returning the abstract valuevalue
as the result of the transfer function.If a subclass overrides this method, the subclass should also override
CFAbstractTransfer.finishValue(CFAbstractValue,CFAbstractStore)
.- Overrides:
finishValue
in 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 ofsecondNode
if the annotationsecondValue
is less precise thanfirstValue
. This is possible, ifsecondNode
is an expression that is tracked by the store (e.g., a local variable or a field). Clients usually call this twice withfirstNode
andsecondNode
reversed, 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
NonNull
for the appropriate branch if an expression is compared to thenull
literal (listed as case 1 in the class description).- Overrides:
strengthenAnnotationOfEqualTo
in 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 theelseStore
instead 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:
visitArrayAccess
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitArrayAccess
in classCFAbstractTransfer<NullnessValue,
NullnessStore, NullnessTransfer>
-
visitInstanceOf
public TransferResult<NullnessValue,NullnessStore> visitInstanceOf(InstanceOfNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitInstanceOf
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitInstanceOf
in classCFAbstractTransfer<NullnessValue,
NullnessStore, NullnessTransfer>
-
visitMethodAccess
public TransferResult<NullnessValue,NullnessStore> visitMethodAccess(MethodAccessNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitMethodAccess
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitMethodAccess
in classAbstractNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>>
-
visitFieldAccess
public TransferResult<NullnessValue,NullnessStore> visitFieldAccess(FieldAccessNode n, TransferInput<NullnessValue, NullnessStore> p) Description copied from class:InitializationTransfer
If an invariant field is initialized and has the invariant annotation, than it has at least the invariant annotation. Note that only fields of the 'this' receiver are tracked for initialization.- Specified by:
visitFieldAccess
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitFieldAccess
in classInitializationTransfer<NullnessValue,
NullnessTransfer, NullnessStore>
-
visitThrow
public TransferResult<NullnessValue,NullnessStore> visitThrow(ThrowNode n, TransferInput<NullnessValue, NullnessStore> p) - Specified by:
visitThrow
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitThrow
in 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:
visitMethodInvocation
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitMethodInvocation
in classInitializationTransfer<NullnessValue,
NullnessTransfer, NullnessStore>
-
visitReturn
public TransferResult<NullnessValue,NullnessStore> visitReturn(ReturnNode n, TransferInput<NullnessValue, NullnessStore> in) - Specified by:
visitReturn
in interfaceNodeVisitor<TransferResult<NullnessValue,
NullnessStore>, TransferInput<NullnessValue, NullnessStore>> - Overrides:
visitReturn
in classCFAbstractTransfer<NullnessValue,
NullnessStore, NullnessTransfer>
-