Class NullnessChecker
- All Implemented Interfaces:
Processor,OptionConfiguration
This checker uses the NullnessNoInitSubchecker to check for nullness and extends the
InitializationChecker to also check that all non-null fields are properly initialized.
You can use the following SuppressWarnings prefixes with this checker:
@SuppressWarnings("nullness")suppresses warnings from the Nullness, Initialization, and KeyFor Checkers@SuppressWarnings("nullnessinitialization")suppresses warnings from the Nullness and Initialization Checkers only, warnings from the KeyFor Checker are not suppressed@SuppressWarnings("nullnesskeyfor")suppresses warnings from the Nullness and KeyFor Checkers only, warnings from the Initialization Checker are not suppressed@SuppressWarnings("nullnessnoinit")has the same effect as@SuppressWarnings("nullnesskeyfor")@SuppressWarnings("nullnessonly")suppresses warnings from the Nullness Checker only, warnings from the Initialization and KeyFor Checkers are not suppressed@SuppressWarnings("initialization")suppresses warnings from the Initialization Checker only, warnings from the Nullness and KeyFor Checkers are not suppressed@SuppressWarnings("keyfor")suppresses warnings from the KeyFor Checker only, warnings from the Nullness and Initialization Checkers are not suppressed
- See Also:
- See the Checker Framework Manual:
- Nullness Checker
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.framework.source.SourceChecker
SourceChecker.CheckerMessage -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanDefault forLINT_MONOTONICNONNULLONSTATIC.static final booleanDefault forLINT_NOINITFORMONOTONICNONNULL.static final booleanDefault forLINT_PERMITCLEARPROPERTY.static final booleanDefault forLINT_REDUNDANTNULLCOMPARISON.static final booleanDefault forLINT_TRUSTARRAYLENZERO.static final StringWarn when@MonotonicNonNullis written on astaticfield, which the manual documents as a code smell that may indicate poor design.static final StringShould we be strict about initialization ofMonotonicNonNullvariables?static final StringIf true, client code may clear system properties.static final StringWarn about redundant comparisons of an expression withnull, if the expression is known to be non-null.static final StringShould the Nullness Checker unsoundly trust@ArrayLen(0)annotations to improve handling ofCollection.toArray()byCollectionToArrayHeuristics?static final StringThe JSpecify compatibility mode.Fields inherited from class org.checkerframework.framework.source.SourceChecker
currentRoot, DETAILS_SEPARATOR, elements, messager, MSGS_FILE, OPTION_SEPARATOR, parentChecker, SUPPRESS_ALL_MESSAGE_KEY, SUPPRESS_ALL_PREFIX, trees, types, UNNEEDED_SUPPRESSION_KEY, upstreamCheckerNames, useAllcheckersPrefix, visitorFields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether to check primitives for initialization.Returns a modifiable set of lower-case strings that are prefixes for SuppressWarnings strings.Class<? extends BaseTypeChecker> The checker for the target type system for which to check initialization.Methods inherited from class org.checkerframework.checker.initialization.InitializationChecker
createSourceVisitor, getAllFields, getImmediateSubcheckerClasses, getTypeFactory, getUpstreamCheckerNames, messageKeyMatchesMethods inherited from class org.checkerframework.common.basetype.BaseTypeChecker
createSourceVisitorPublic, getAnnotationProvider, getTypeFactoryOfSubcheckerOrNull, getUltimateParentChecker, getVisitor, invokeConstructorFor, isElementAnnotatedForThisCheckerOrUpstreamChecker, processErrorMessageArg, shouldAddShutdownHook, shutdownHookMethods inherited from class org.checkerframework.framework.source.SourceChecker
addOptionsForMode, createMessagesProperties, createRelevantJavaTypes, createSupportedLintOptions, createSupportedModes, expandCFOptions, expandCFOptions, fullMessageOf, getAssumeAssertions, getBooleanOption, getBooleanOption, getClassHierarchy, getElementUtils, getErrorCount, getExtraStubFiles, getLintOption, getLintOption, getOption, getOption, getOptionConfiguration, getOptions, getOptionsNoSubcheckers, getParentChecker, getPathToCompilationUnit, getProcessingEnvironment, getProperties, getRelatedClassName, getRelevantJavaTypes, getStandardSuppressWarningsPrefixes, getStringsOption, getStringsOption, getStubFiles, getSubchecker, getSubCheckerIndex, getSubcheckers, getSupportedAnnotationTypes, getSupportedLintOptions, getSupportedModes, getSupportedOptions, getSupportedSourceVersion, getSuppressWarningsPrefixesOfSubcheckers, getTreePathCacher, getTreeUtils, getTypeUtils, getWarningMessagePrefix, handleProcessingError, hasOption, hasOptionNoSubcheckers, init, initChecker, instantiateSubcheckers, message, message, packageProcess, printStats, printStoredMessages, report, reportError, reportWarning, setDiagnosticSink, setHostOptions, setLintOption, setParentChecker, setRoot, shouldResolveReflection, shouldSkipDefs, shouldSkipDefs, shouldSkipDefs, shouldSkipDefs, shouldSkipFiles, shouldSkipUses, shouldSkipUses, shouldSuppressWarnings, shouldSuppressWarnings, shouldSuppressWarnings, suppressWarningsString, typeProcess, typeProcessingOver, typeProcessingStart, useConservativeDefault, usePermissiveDefault, warnUnneededSuppressions, warnUnneededSuppressionsMethods inherited from class org.checkerframework.javacutil.AbstractTypeProcessor
getCompilerLog, isExternallyDriven, packageProcessExternally, process, setExternallyDriven, typeProcessExternally, typeProcessingOverExternallyMethods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, isInitializedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.checkerframework.framework.util.OptionConfiguration
getStringsOption, getStringsOption
-
Field Details
-
MODE_JSPECIFY
The JSpecify compatibility mode.MODE_JSPECIFYrestricts checking to code in the scope of an@AnnotatedFor, treats@NullMarkedas a defaulting annotation, and turns off the initialization and map-key checks, none of which JSpecify specifies. It also assumes that every called method is pure and that assertions are enabled. Code outside such a scope has what JSpecify calls unspecified nullness, which JSpecify lets each tool treat anywhere from strictly to leniently; see the "multiple worlds" discussion in the JSpecify specification. The mode currently interprets it leniently, with permissive defaults for both source code and bytecode, unless the command line chooses conservative defaults.- See Also:
-
LINT_NOINITFORMONOTONICNONNULL
Should we be strict about initialization ofMonotonicNonNullvariables?- See Also:
-
LINT_DEFAULT_NOINITFORMONOTONICNONNULL
public static final boolean LINT_DEFAULT_NOINITFORMONOTONICNONNULLDefault forLINT_NOINITFORMONOTONICNONNULL.- See Also:
-
LINT_REDUNDANTNULLCOMPARISON
Warn about redundant comparisons of an expression withnull, if the expression is known to be non-null.- See Also:
-
LINT_DEFAULT_REDUNDANTNULLCOMPARISON
public static final boolean LINT_DEFAULT_REDUNDANTNULLCOMPARISONDefault forLINT_REDUNDANTNULLCOMPARISON.- See Also:
-
LINT_TRUSTARRAYLENZERO
Should the Nullness Checker unsoundly trust@ArrayLen(0)annotations to improve handling ofCollection.toArray()byCollectionToArrayHeuristics?- See Also:
-
LINT_DEFAULT_TRUSTARRAYLENZERO
public static final boolean LINT_DEFAULT_TRUSTARRAYLENZERODefault forLINT_TRUSTARRAYLENZERO.- See Also:
-
LINT_PERMITCLEARPROPERTY
If true, client code may clear system properties. If false (the default), some calls toSystem.getPropertyare refined to return @NonNull.- See Also:
-
LINT_DEFAULT_PERMITCLEARPROPERTY
public static final boolean LINT_DEFAULT_PERMITCLEARPROPERTYDefault forLINT_PERMITCLEARPROPERTY.- See Also:
-
LINT_MONOTONICNONNULLONSTATIC
Warn when@MonotonicNonNullis written on astaticfield, which the manual documents as a code smell that may indicate poor design.- See Also:
-
LINT_DEFAULT_MONOTONICNONNULLONSTATIC
public static final boolean LINT_DEFAULT_MONOTONICNONNULLONSTATICDefault forLINT_MONOTONICNONNULLONSTATIC.- See Also:
-
-
Constructor Details
-
NullnessChecker
public NullnessChecker()Default constructor for NullnessChecker.
-
-
Method Details
-
checkPrimitives
public boolean checkPrimitives()Description copied from class:InitializationCheckerWhether to check primitives for initialization.- Specified by:
checkPrimitivesin classInitializationChecker- Returns:
- whether to check primitives for initialization
-
getTargetCheckerClass
Description copied from class:InitializationCheckerThe checker for the target type system for which to check initialization.- Specified by:
getTargetCheckerClassin classInitializationChecker- Returns:
- the checker for the target type system.
-
getSuppressWarningsPrefixes
Description copied from class:SourceCheckerReturns a modifiable set of lower-case strings that are prefixes for SuppressWarnings strings.The collection must not be empty and must not contain only
SourceChecker.SUPPRESS_ALL_PREFIX.This method is related to
SourceChecker.getUpstreamCheckerNames(). By default, the returned set includes lower-case prefixes derived from all checker names returned bySourceChecker.getUpstreamCheckerNames(), unless this checker class has aSuppressWarningsPrefixmeta-annotation.- Overrides:
getSuppressWarningsPrefixesin classInitializationChecker- Returns:
- non-empty modifiable set of lower-case prefixes for SuppressWarnings strings
- See Also:
-