Class NullnessVisitor
- All Implemented Interfaces:
- TreeVisitor<Void,- Void> 
- 
Nested Class SummaryNested classes/interfaces inherited from class org.checkerframework.common.basetype.BaseTypeVisitorBaseTypeVisitor.OverrideChecker
- 
Field SummaryFields inherited from class org.checkerframework.checker.initialization.InitializationVisitorannoFormatter, initializedFieldsFields inherited from class org.checkerframework.common.basetype.BaseTypeVisitoratypeFactory, checker, DETERMINISTIC, IMPURE, methodTree, positions, PURE, qualHierarchy, showchecks, SIDE_EFFECT_FREE, TARGET, targetValueElement, typeValidator, unusedWhenElementFields inherited from class org.checkerframework.framework.source.SourceVisitorelements, root, trees, treesWithSuppressWarnings, types
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidIssue error if the exception parameter is not a supertype of the annotation specified byBaseTypeVisitor.getExceptionParameterLowerBoundAnnotations(), which is top by default.protected voidReports an error if a comparison of a @NonNull expression with the null literal is performed.protected voidcheckMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree tree) Tests whether the method can be invoked using the receiver of the 'tree' method invocation, and issues a "method.invocation" if the invocation is invalid.protected voidCase 4: Check for thrown exception nullness.protected booleancommonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.protected booleancommonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.protected booleancommonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs) Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.Constructs an instance of the appropriate type factory for the implemented type system.protected TypeValidatorbooleanisValidUse(AnnotatedTypeMirror.AnnotatedPrimitiveType type, Tree tree) Tests that the qualifiers present on the primitive type are valid.voidprocessClassTree(ClassTree classTree) Type-check classTree.voidvisitAnnotatedType(@Nullable List<? extends AnnotationTree> annoTrees, Tree typeTree) Checks an annotated type.visitAnnotation(AnnotationTree tree, Void p) Ensure that the annotation arguments comply to their declarations.visitArrayAccess(ArrayAccessTree tree, Void p) Case 3: Check for array dereferencing.visitAssert(AssertTree tree, Void p) visitBinary(BinaryTree tree, Void p) Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations.Case 7: unboxing case: primitive operation.If the computation of the type of the ConditionalExpressionTree in org.checkerframework.framework.type.TypeFromTree.TypeFromExpression.visitConditionalExpression(ConditionalExpressionTree, AnnotatedTypeFactory) is correct, the following checks are redundant.visitDoWhileLoop(DoWhileLoopTree tree, Void p) visitEnhancedForLoop(EnhancedForLoopTree tree, Void p) Case 2: Check for implicit.iteratorcall.visitForLoop(ForLoopTree tree, Void p) visitInstanceOf(InstanceOfTree tree, Void p) visitMemberSelect(MemberSelectTree tree, Void p) Case 1: Check for null dereferencing.visitMethod(MethodTree tree, Void p) Checks that the method or constructor obeys override and subtype rules to all overridden methods.Performs a method invocation check.visitNewArray(NewArrayTree tree, Void p) visitNewClass(NewClassTree tree, Void p) Performs a new class invocation check.visitSwitch(SwitchTree tree, Void p) visitSynchronized(SynchronizedTree tree, Void p) Case 5: Check for synchronizing locks.visitTypeCast(TypeCastTree tree, Void p) Case 7: unboxing case: casting to a primitive.visitUnary(UnaryTree tree, Void p) Case 7: unboxing case: primitive operation.visitWhileLoop(WhileLoopTree tree, Void p) Methods inherited from class org.checkerframework.checker.initialization.InitializationVisitorcheckConstructorInvocation, checkConstructorResult, checkContract, checkFieldsInitialized, checkThisOrSuperConstructorCall, setRoot, visitVariableMethods inherited from class org.checkerframework.common.basetype.BaseTypeVisitorcheckAccess, checkAccessAllowed, checkArguments, checkArrayInitialization, checkConditionalPostcondition, checkDefaultConstructor, checkExplicitAnnotationsOnIntersectionBounds, checkExtendsAndImplements, checkExtendsOrImplements, checkFieldInvariantDeclarations, checkForPolymorphicQualifiers, checkForPolymorphicQualifiers, checkMethodReferenceAsOverride, checkOverride, checkOverride, checkPostcondition, checkPreconditions, checkPurity, checkQualifierParameter, checkSuperConstructorCall, checkThisConstructorCall, checkTypeArguments, checkTypecastRedundancy, checkTypecastSafety, checkVarargs, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckEndDiagnostic, commonAssignmentCheckStartDiagnostic, createOverrideChecker, createTypeFactoryPublic, enclosingMemberSelect, enclosingStatement, getExceptionParameterLowerBoundAnnotations, getThrowUpperBoundAnnotations, getTypeFactory, isTypeCastSafe, isValidUse, isValidUse, reportMethodInvocabilityError, reportPurityErrors, scan, shouldSkipUses, shouldWarnAboutIrrelevantJavaTypes, skipReceiverSubtypeCheck, testAnnotationInsertion, testJointJavacJavaParserVisitor, testTypevarContainment, typeCheckVectorCopyIntoArgument, validateType, validateTypeOf, visitAnnotatedType, visitAssignment, visitCatch, visitClass, visitCompilationUnit, visitIdentifier, visitLambdaExpression, visitMemberReference, visitReturn, visitSwitchExpression17, visitThrow, visitTypeParameter, warnAboutIrrelevantJavaTypes, warnRedundantAnnotationsMethods inherited from class org.checkerframework.framework.source.SourceVisitorvisitMethods inherited from class com.sun.source.util.TreePathScannergetCurrentPath, scanMethods inherited from class com.sun.source.util.TreeScannerreduce, scan, visitArrayType, visitBindingPattern, visitBlock, visitBreak, visitCase, visitContinue, visitDefaultCaseLabel, visitEmptyStatement, visitErroneous, visitExports, visitExpressionStatement, visitGuardedPattern, visitImport, visitIntersectionType, visitLabeledStatement, visitLiteral, visitModifiers, visitModule, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitParenthesizedPattern, visitPrimitiveType, visitProvides, visitRequires, visitSwitchExpression, visitTry, visitUnionType, visitUses, visitWildcard, visitYield
- 
Constructor Details- 
NullnessVisitorCreate a new NullnessVisitor.- Parameters:
- checker- the checker to which this visitor belongs
 
 
- 
- 
Method Details- 
createTypeFactoryDescription copied from class:BaseTypeVisitorConstructs an instance of the appropriate type factory for the implemented type system.The default implementation uses the checker naming convention to create the appropriate type factory. If no factory is found, it returns BaseAnnotatedTypeFactory. It reflectively invokes the constructor that accepts this checker and compilation unit tree (in that order) as arguments.Subclasses have to override this method to create the appropriate visitor if they do not follow the checker naming convention. - Overrides:
- createTypeFactoryin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Returns:
- the appropriate type factory
 
- 
isValidUseDescription copied from class:BaseTypeVisitorTests that the qualifiers present on the primitive type are valid.- Overrides:
- isValidUsein class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- type- the use of the primitive type
- tree- the tree where the type is used
- Returns:
- true if the type is a valid use of the primitive type
 
- 
commonAssignmentCheckprotected boolean commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitorChecks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.- Overrides:
- commonAssignmentCheckin class- InitializationVisitor<NullnessAnnotatedTypeFactory,- NullnessValue, - NullnessStore> 
- Parameters:
- varTree- the AST node for the lvalue (usually a variable)
- valueExp- the AST node for the rvalue (the new value)
- errorKey- the error message key to use if the check fails
- extraArgs- arguments to the error message key, before "found" and "expected" types
- Returns:
- true if the check succeeds, false if an error message was issued
 
- 
commonAssignmentCheckprotected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, ExpressionTree valueExp, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitorChecks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.- Overrides:
- commonAssignmentCheckin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- varType- the annotated type for the lvalue (usually a variable)
- valueExp- the AST node for the rvalue (the new value)
- errorKey- the error message key to use if the check fails
- extraArgs- arguments to the error message key, before "found" and "expected" types
- Returns:
- true if the check succeeds, false if an error message was issued
 
- 
commonAssignmentCheck@FormatMethod protected boolean commonAssignmentCheck(AnnotatedTypeMirror varType, AnnotatedTypeMirror valueType, Tree valueTree, @CompilerMessageKey String errorKey, Object... extraArgs) Description copied from class:BaseTypeVisitorChecks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.- Overrides:
- commonAssignmentCheckin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- varType- the annotated type of the variable
- valueType- the annotated type of the value
- valueTree- the location to use when reporting the error message
- errorKey- the error message key to use if the check fails
- extraArgs- arguments to the error message key, before "found" and "expected" types
- Returns:
- true if the check succeeds, false if an error message was issued
 
- 
visitMemberSelectCase 1: Check for null dereferencing.- Specified by:
- visitMemberSelectin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitMemberSelectin class- TreeScanner<Void,- Void> 
 
- 
visitEnhancedForLoopCase 2: Check for implicit.iteratorcall.- Specified by:
- visitEnhancedForLoopin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitEnhancedForLoopin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
visitArrayAccessCase 3: Check for array dereferencing.- Specified by:
- visitArrayAccessin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitArrayAccessin class- TreeScanner<Void,- Void> 
 
- 
visitNewArray- Specified by:
- visitNewArrayin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitNewArrayin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
checkThrownExpressionCase 4: Check for thrown exception nullness.- Overrides:
- checkThrownExpressionin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- tree- a ThrowTree to check
 
- 
visitSynchronizedCase 5: Check for synchronizing locks.- Specified by:
- visitSynchronizedin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitSynchronizedin class- TreeScanner<Void,- Void> 
 
- 
visitAssert- Specified by:
- visitAssertin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitAssertin class- TreeScanner<Void,- Void> 
 
- 
visitIf- Specified by:
- visitIfin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitIfin class- TreeScanner<Void,- Void> 
 
- 
visitInstanceOf- Specified by:
- visitInstanceOfin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitInstanceOfin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
checkForRedundantTestsReports an error if a comparison of a @NonNull expression with the null literal is performed.- Parameters:
- tree- a tree that might be a comparison of a @NonNull expression with the null literal
 
- 
visitBinaryCase 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations.- Specified by:
- visitBinaryin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitBinaryin class- TreeScanner<Void,- Void> 
 
- 
visitUnaryCase 7: unboxing case: primitive operation.- Specified by:
- visitUnaryin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitUnaryin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
visitCompoundAssignmentCase 7: unboxing case: primitive operation.- Specified by:
- visitCompoundAssignmentin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitCompoundAssignmentin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
visitTypeCastCase 7: unboxing case: casting to a primitive.- Specified by:
- visitTypeCastin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitTypeCastin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
visitMethodDescription copied from class:BaseTypeVisitorChecks that the method or constructor obeys override and subtype rules to all overridden methods. (Uses the pseudo-assignment logic to do so.)The override rule specifies that a method, m1, may override a method m2 only if: - m1 return type is a subtype of m2
- m1 receiver type is a supertype of m2
- m1 parameters are supertypes of corresponding m2 parameters
 - Specified by:
- visitMethodin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitMethodin class- InitializationVisitor<NullnessAnnotatedTypeFactory,- NullnessValue, - NullnessStore> 
 
- 
visitMethodInvocationDescription copied from class:BaseTypeVisitorPerforms a method invocation check.An invocation of a method, m, on the receiver, r is valid only if: - passed arguments are subtypes of corresponding m parameters
- r is a subtype of m receiver type
- if m is generic, passed type arguments are subtypes of m type variables
 - Specified by:
- visitMethodInvocationin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitMethodInvocationin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
processClassTreeDescription copied from class:BaseTypeVisitorType-check classTree. Subclasses should override this method instead ofBaseTypeVisitor.visitClass(ClassTree, Void).- Overrides:
- processClassTreein class- InitializationVisitor<NullnessAnnotatedTypeFactory,- NullnessValue, - NullnessStore> 
- Parameters:
- classTree- class to check
 
- 
checkMethodInvocabilityprotected void checkMethodInvocability(AnnotatedTypeMirror.AnnotatedExecutableType method, MethodInvocationTree tree) Description copied from class:BaseTypeVisitorTests whether the method can be invoked using the receiver of the 'tree' method invocation, and issues a "method.invocation" if the invocation is invalid.This implementation tests whether the receiver in the method invocation is a subtype of the method receiver type. This behavior can be specialized by overriding skipReceiverSubtypeCheck. - Overrides:
- checkMethodInvocabilityin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- method- the type of the invoked method
- tree- the method invocation tree
 
- 
visitSwitch- Specified by:
- visitSwitchin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitSwitchin class- TreeScanner<Void,- Void> 
 
- 
visitForLoop- Specified by:
- visitForLoopin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitForLoopin class- TreeScanner<Void,- Void> 
 
- 
visitNewClassDescription copied from class:BaseTypeVisitorPerforms a new class invocation check.An invocation of a constructor, c, is valid only if: - passed arguments are subtypes of corresponding c parameters
- if c is generic, passed type arguments are subtypes of c type variables
 - Specified by:
- visitNewClassin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitNewClassin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
visitWhileLoop- Specified by:
- visitWhileLoopin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitWhileLoopin class- TreeScanner<Void,- Void> 
 
- 
visitDoWhileLoop- Specified by:
- visitDoWhileLoopin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitDoWhileLoopin class- TreeScanner<Void,- Void> 
 
- 
visitConditionalExpressionDescription copied from class:BaseTypeVisitorIf the computation of the type of the ConditionalExpressionTree in org.checkerframework.framework.type.TypeFromTree.TypeFromExpression.visitConditionalExpression(ConditionalExpressionTree, AnnotatedTypeFactory) is correct, the following checks are redundant. However, let's add another failsafe guard and do the checks.- Specified by:
- visitConditionalExpressionin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitConditionalExpressionin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
checkExceptionParameterDescription copied from class:BaseTypeVisitorIssue error if the exception parameter is not a supertype of the annotation specified byBaseTypeVisitor.getExceptionParameterLowerBoundAnnotations(), which is top by default.Subclasses may override this method to change the behavior of this check. Subclasses wishing to enforce that exception parameter be annotated with other annotations can just override BaseTypeVisitor.getExceptionParameterLowerBoundAnnotations().- Overrides:
- checkExceptionParameterin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- tree- a CatchTree to check
 
- 
visitAnnotationDescription copied from class:BaseTypeVisitorEnsure that the annotation arguments comply to their declarations. This needs some special casing, as annotation arguments form special trees.- Specified by:
- visitAnnotationin interface- TreeVisitor<Void,- Void> 
- Overrides:
- visitAnnotationin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
- 
visitAnnotatedTypeDescription copied from class:BaseTypeVisitorChecks an annotated type. Invoked byBaseTypeVisitor.visitAnnotatedType(AnnotatedTypeTree, Void),BaseTypeVisitor.visitVariable(com.sun.source.tree.VariableTree, java.lang.Void), andBaseTypeVisitor.visitMethod(com.sun.source.tree.MethodTree, java.lang.Void). Exists to prevent code duplication among the three. Checking invisitVariableandvisitMethodis needed because there isn't an AnnotatedTypeTree within a variable declaration or for a method return type -- all the annotations are attached to the VariableTree or MethodTree, respectively.- Overrides:
- visitAnnotatedTypein class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
- Parameters:
- annoTrees- annotations written before a variable/method declaration, if this type is from one; null otherwise. This might contain type annotations that the Java parser attached to the declaration rather than to the type.
- typeTree- the type that any type annotations in annoTrees apply to
 
- 
createTypeValidator- Overrides:
- createTypeValidatorin class- BaseTypeVisitor<NullnessAnnotatedTypeFactory>
 
 
-