Class IndexChecker
- All Implemented Interfaces:
Processor
,OptionConfiguration
The checkers run in this order:
Constant Value Checker, SameLen Checker, SearchIndex Checker, Lower Bound Checker, Upper Bound Checker
The Constant Value Checker has no dependencies, but it does trust Positive annotations from the Lower Bound Checker. This means that if the Value Checker is run on code containing Positive annotations, then the Lower Bound Checker also needs to be run to guarantee soundness.
The SameLen Checker has no dependencies.
The SearchIndex Checker depends only on the Value Checker, which it uses to refine SearchIndexFor types to NegativeIndexFor types by comparing to compile-time constants of zero or negative one.
The Lower Bound Checker depends only on the Value Checker. It uses the Value Checker to:
- give appropriate types to compile time constants. For example, the type of 7 is Positive, 0 is NonNegative, etc.
- in a subtraction expression of the form
a.length - x
, if x is a compile-time constant, and if the minimum length of a > x, the resulting expression is non-negative. - when typing an array length (i.e.
a.length
), if the minimum length of the array is ≥ 1, then the type is @Positive; if its MinLen is zero, then the type is @NonNegative.
The Upper Bound Checker depends on all three other checkers.
Value dependencies in the UBC:
- When computing offsets, the UBC replaces compile-time constants with their known values (though it also keeps an offset with the variable's name, if applicable).
- The UBC has relaxed assignment rules: it allows assignments where the right hand side is a value known at compile time and the type of the left hand side is annotated with LT*LengthOf("a"). If the minimum length of a is in the correct relationship with the value on the right hand side, then the assignment is legal.
- When checking whether an array access is legal, the UBC first checks the upper bound type of the index. If that fails, it checks if the index is a compile-time constant. If it is, then it queries the Value Checker to determine if the array is guaranteed to be longer than the value of the constant. If it is, the access is safe.
- When compile time constants would improve the precision of reasoning about arithmetic, the UBC queries the Value Checker for their values. For instance, dividing a value with type LTLengthOf by a compile-time constant of 1 is guaranteed to result in another LTLengthOf for the same arrays.
SameLen dependencies in the UBC:
- When checking whether an array access is legal, the UBC first checks the upper bound type. If it's an LTL (or LTOM/LTEL), then it collects, from the SameLen Checker, the list of arrays that are known to be the same length as the array being accessed. Then the annotation is checked to see if it is valid for any of the arrays in question.
Lower Bound dependencies in UBC:
- When an array is created with length equal to the sum of two quantities, if one of the quantities is non-negative, the other becomes LTEL of the new array. If one is positive, the other becomes LTL.
- When a non-negative is subtracted from an LTL, it stays LTL.
- See the Checker Framework Manual:
- Index Checker
-
Field Summary
Fields inherited from class org.checkerframework.checker.index.upperbound.UpperBoundChecker
ltEqLengthOfValueElement, ltLengthOfOffsetElement, ltLengthOfValueElement, ltOMLengthOfValueElement, substringIndexForOffsetElement, substringIndexForValueElement, upperBoundLiteralValueElement
Fields inherited from class org.checkerframework.framework.source.SourceChecker
currentRoot, DETAILS_SEPARATOR, elements, elementsWithSuppressedWarnings, errsOnLastExit, javacErrored, messager, messagesProperties, MSGS_FILE, OPTION_SEPARATOR, parentChecker, SUPPRESS_ALL_MESSAGE_KEY, SUPPRESS_ALL_PREFIX, trees, types, UNNEEDED_SUPPRESSION_KEY, upstreamCheckerNames, useAllcheckersPrefix, visitor
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
-
Method Summary
Methods inherited from class org.checkerframework.checker.index.upperbound.UpperBoundChecker
getImmediateSubcheckerClasses, initChecker, shouldSkipUses
Methods inherited from class org.checkerframework.common.basetype.BaseTypeChecker
createSourceVisitor, createSourceVisitorPublic, getAnnotationProvider, getExtraStubFiles, getOptions, getOptionsNoSubcheckers, getRelatedClassName, getSubchecker, getSubcheckers, getSupportedLintOptions, getSupportedOptions, getSuppressWarningsPrefixesOfSubcheckers, getTreePathCacher, getTypeFactory, getTypeFactoryOfSubchecker, getUltimateParentChecker, getVisitor, hasOptionNoSubcheckers, invokeConstructorFor, printOrStoreMessage, processArg, reportJavacError, setRoot, shouldAddShutdownHook, shouldResolveReflection, shutdownHook, typeProcess, typeProcessingOver, warnUnneededSuppressions
Methods inherited from class org.checkerframework.framework.source.SourceChecker
addOptions, createSupportedLintOptions, expandCFOptions, fullMessageOf, getBooleanOption, getBooleanOption, getElementUtils, getLintOption, getLintOption, getMessagesProperties, getOption, getOption, getOptionConfiguration, getParentChecker, getPathToCompilationUnit, getProcessingEnvironment, getProperties, getStandardSuppressWarningsPrefixes, getSupportedAnnotationTypes, getSupportedSourceVersion, getSuppressWarningsPrefixes, getTreeUtils, getTypeUtils, getUpstreamCheckerNames, hasOption, init, message, message, printOrStoreMessage, printStats, report, reportError, reportWarning, setLintOption, setParentChecker, setProcessingEnvironment, setSupportedLintOptions, shouldSkipDefs, shouldSkipDefs, shouldSkipUses, shouldSuppressWarnings, shouldSuppressWarnings, shouldSuppressWarnings, typeProcessingStart, useConservativeDefault, warnUnneededSuppressions
Methods inherited from class org.checkerframework.javacutil.AbstractTypeProcessor
getCompilerLog, process
Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, isInitialized
-
Constructor Details
-
IndexChecker
public IndexChecker()Creates the Index Checker.
-