Class ResourceLeakChecker
- All Implemented Interfaces:
Processor,OptionConfiguration
MustCall annotations and defines a set of ignored
exceptions. This checker calls the RLCCalledMethodsChecker as a direct subchecker, which
then in turn calls the MustCallChecker as a subchecker, and afterwards this checker
traverses the CFG to check whether all MustCall obligations are fulfilled.
The checker hierarchy is: this "empty" RLC → RLCCalledMethodsChecker → MustCallChecker
The MustCallChecker is a subchecker of the RLCCm checker (instead of a sibling), since we want them to operate on the same CFG (so we can get both a CM and MC store for a given CFG block), which only works if one of them is a subchecker of the other.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.framework.source.SourceChecker
SourceChecker.CheckerMessage -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCommand-line option for counting how many must-call obligations were checked by the Resource Leak Checker, and emitting the number after processing all files.static final StringThe Returns Receiver Checker is disabled by default for the Resource Leak Checker, as it adds significant overhead and typically provides little benefit.static final StringCommand-line option for controlling which exceptions are ignored.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 TypeMethodDescriptionprotected @Nullable TypeMirrorCheck if the given String refers to an actual type.protected PropertiesCreates the mapping of error keys to custom error messages.Returns the set of exceptions that should be ignored.protected Set<Class<? extends SourceChecker>> Returns the list of independent subcheckers to be run together.Returns a modifiable set of lower-case strings that are prefixes for SuppressWarnings strings.protected @Nullable SetOfTypesparseExceptionSpecifier(String exceptionSpecifier, String ignoredExceptionsOptionValue) Parse a single exception specifier from theIGNORED_EXCEPTIONSoption and issue warnings if it does not parse.protected SetOfTypesparseIgnoredExceptions(String ignoredExceptionsOptionValue) Parse the argument given for theIGNORED_EXCEPTIONSoption.voidreportError(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args) Reports an error.voidsetRoot(CompilationUnitTree newRoot) Invoked when the current compilation unit root changes.voidA method to be called once all the classes are processed.Methods inherited from class org.checkerframework.framework.source.AggregateChecker
createSourceVisitor, getImmediateSubcheckerClassesMethods inherited from class org.checkerframework.framework.source.SourceChecker
addOptionsForMode, createRelevantJavaTypes, createSupportedLintOptions, createSupportedModes, expandCFOptions, expandCFOptions, fullMessageOf, getAnnotationProvider, 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, getUpstreamCheckerNames, getVisitor, getWarningMessagePrefix, handleProcessingError, hasOption, hasOptionNoSubcheckers, init, initChecker, instantiateSubcheckers, isElementAnnotatedForThisCheckerOrUpstreamChecker, message, message, messageKeyMatches, packageProcess, printStats, printStoredMessages, processErrorMessageArg, report, reportWarning, setDiagnosticSink, setHostOptions, setLintOption, setParentChecker, shouldAddShutdownHook, shouldResolveReflection, shouldSkipDefs, shouldSkipDefs, shouldSkipDefs, shouldSkipDefs, shouldSkipFiles, shouldSkipUses, shouldSkipUses, shouldSuppressWarnings, shouldSuppressWarnings, shouldSuppressWarnings, shutdownHook, suppressWarningsString, typeProcess, 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
-
COUNT_MUST_CALL
Command-line option for counting how many must-call obligations were checked by the Resource Leak Checker, and emitting the number after processing all files. Used for generating tables for a research paper. Not of interest to most users.- See Also:
-
IGNORED_EXCEPTIONS
Command-line option for controlling which exceptions are ignored.- See Also:
-
ENABLE_RETURNS_RECEIVER
The Returns Receiver Checker is disabled by default for the Resource Leak Checker, as it adds significant overhead and typically provides little benefit. To enable it, use the -AenableReturnsReceiverForRlc flag.- See Also:
-
-
Constructor Details
-
ResourceLeakChecker
public ResourceLeakChecker()Creates a ResourceLeakChecker.
-
-
Method Details
-
createMessagesProperties
Description copied from class:SourceCheckerCreates the mapping of error keys to custom error messages.As a default, this implementation builds a
Propertiesout of filemessages.properties. It accumulates all the properties files in the Java class hierarchy from the checker up toSourceChecker. This permits subclasses to inherit default messages while being able to override them.SourceChecker.initChecker()calls this method once and uses the result for every diagnostic.- Overrides:
createMessagesPropertiesin classSourceChecker- Returns:
- a
Propertiesthat maps error keys to error message text
-
getSupportedCheckers
Description copied from class:AggregateCheckerReturns the list of independent subcheckers to be run together. An aggregate checker overrides this method to indicate its immediate subcheckers.- Specified by:
getSupportedCheckersin classAggregateChecker- Returns:
- the list of immediate subcheckers checkers to be run
-
reportError
public void reportError(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args) Description copied from class:SourceCheckerReports an error. By default, prints it to the screen via the compiler's internal messager.Prefer a Tree: pass an Element only for a declaration that has none, such as one read from bytecode. Under a host that collects diagnostics, such as the Error Prone plugin, an Element declared in the current compilation unit is reported on its declaration; any other Element is reported directly to javac, bypassing the host's severity and suppression.
- Overrides:
reportErrorin classSourceChecker- Parameters:
source- the source position information; may be an Element or a Tree. Null means the error has no source position -- for example, it is issued while the checker is initializing, before any source file is processed -- and is reported against the compilation as a whole.messageKey- the message keyargs- arguments for interpolation in the string corresponding to the given message key
-
typeProcessingOver
public void typeProcessingOver()Description copied from class:AbstractTypeProcessorA method to be called once all the classes are processed.Subclasses may override this method to do any aggregate analysis (e.g. generate report, persistence) or resource deallocation.
Method
AbstractTypeProcessor.getCompilerLog()can be used to access the number of compiler errors.- Overrides:
typeProcessingOverin classSourceChecker
-
getIgnoredExceptions
Returns the set of exceptions that should be ignored. This set comes from theIGNORED_EXCEPTIONSoption if it was provided, orDEFAULT_IGNORED_EXCEPTIONSif not.- Returns:
- the set of exceptions to ignore
-
parseIgnoredExceptions
Parse the argument given for theIGNORED_EXCEPTIONSoption. Warnings will be issued for any problems in the argument, for instance if any of the named exceptions cannot be found.- Parameters:
ignoredExceptionsOptionValue- the value given forIGNORED_EXCEPTIONS- Returns:
- the set of ignored exceptions
-
parseExceptionSpecifier
protected @Nullable SetOfTypes parseExceptionSpecifier(String exceptionSpecifier, String ignoredExceptionsOptionValue) Parse a single exception specifier from theIGNORED_EXCEPTIONSoption and issue warnings if it does not parse. SeeEXCEPTION_SPECIFIERfor a description of the syntax.- Parameters:
exceptionSpecifier- the exception specifier to parseignoredExceptionsOptionValue- the whole value of theIGNORED_EXCEPTIONSoption; only used for error reporting- Returns:
- the parsed set of types, or null if the value does not parse
-
checkCanonicalName
Check if the given String refers to an actual type.- Parameters:
s- any string- Returns:
- the referenced type, or null if it does not exist
-
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 classSourceChecker- Returns:
- non-empty modifiable set of lower-case prefixes for SuppressWarnings strings
- See Also:
-
setRoot
Description copied from class:SourceCheckerInvoked when the current compilation unit root changes.- Overrides:
setRootin classSourceChecker- Parameters:
newRoot- the new compilation unit root
-