Class ResourceLeakChecker

All Implemented Interfaces:
Processor, OptionConfiguration

@SupportedOptions({"permitStaticOwning","permitInitializationLeak","countMustCall","resourceLeakIgnoredExceptions","noCreatesMustCallFor","noLightweightOwnership","noResourceAliases","enableWpiForRlc","enableReturnsReceiverForRlc"}) public class ResourceLeakChecker extends AggregateChecker
The entry point for the Resource Leak Checker. This checker only counts the number of 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.

  • Field Details

    • COUNT_MUST_CALL

      public static final String 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

      public static final String IGNORED_EXCEPTIONS
      Command-line option for controlling which exceptions are ignored.
      See Also:
    • ENABLE_WPI_FOR_RLC

      public static final String ENABLE_WPI_FOR_RLC
      Ordinarily, when the -Ainfer flag is used, whole-program inference is run for every checker and sub-checker. However, the Resource Leak Checker is different. The -Ainfer flag enables the RLC's own (non-WPI) inference mechanism (MustCallInference). To use WPI in addition to this mechanism for its sub-checkers, use the -AenableWpiForRlc flag, which is intended only for testing and experiments.
      See Also:
    • ENABLE_RETURNS_RECEIVER

      public static final String 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

    • getSupportedCheckers

      protected Set<Class<? extends SourceChecker>> getSupportedCheckers()
      Description copied from class: AggregateChecker
      Returns the list of independent subcheckers to be run together. An aggregate checker overrides this method to indicate its immediate subcheckers.
      Specified by:
      getSupportedCheckers in class AggregateChecker
      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: SourceChecker
      Reports an error. By default, prints it to the screen via the compiler's internal messager.
      Overrides:
      reportError in class SourceChecker
      Parameters:
      source - the source position information; may be an Element, a Tree, or null
      messageKey - the message key
      args - arguments for interpolation in the string corresponding to the given message key
    • typeProcessingOver

      public void typeProcessingOver()
      Description copied from class: AbstractTypeProcessor
      A 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:
      typeProcessingOver in class SourceChecker
    • getIgnoredExceptions

      public SetOfTypes getIgnoredExceptions()
      Returns the set of exceptions that should be ignored. This set comes from the IGNORED_EXCEPTIONS option if it was provided, or DEFAULT_IGNORED_EXCEPTIONS if not.
      Returns:
      the set of exceptions to ignore
    • parseIgnoredExceptions

      protected SetOfTypes parseIgnoredExceptions(String ignoredExceptionsOptionValue)
      Parse the argument given for the IGNORED_EXCEPTIONS option. 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 for IGNORED_EXCEPTIONS
      Returns:
      the set of ignored exceptions
    • parseExceptionSpecifier

      protected @Nullable SetOfTypes parseExceptionSpecifier(String exceptionSpecifier, String ignoredExceptionsOptionValue)
      Parse a single exception specifier from the IGNORED_EXCEPTIONS option and issue warnings if it does not parse. See EXCEPTION_SPECIFIER for a description of the syntax.
      Parameters:
      exceptionSpecifier - the exception specifier to parse
      ignoredExceptionsOptionValue - the whole value of the IGNORED_EXCEPTIONS option; only used for error reporting
      Returns:
      the parsed set of types, or null if the value does not parse
    • checkCanonicalName

      protected @Nullable TypeMirror checkCanonicalName(String s)
      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

      public NavigableSet<String> getSuppressWarningsPrefixes()
      Description copied from class: SourceChecker
      Returns 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.

      Overrides:
      getSuppressWarningsPrefixes in class SourceChecker
      Returns:
      non-empty modifiable set of lower-case prefixes for SuppressWarnings strings