Class ResourceLeakChecker

All Implemented Interfaces:
Processor, OptionConfiguration

@SupportedOptions({"permitStaticOwning","permitInitializationLeak","countMustCall","resourceLeakIgnoredExceptions","noCreatesMustCallFor","noLightweightOwnership","noResourceAliases","enableWpiForRlc"}) @StubFiles("IOUtils.astub") public class ResourceLeakChecker extends CalledMethodsChecker
The entry point for the Resource Leak Checker. This checker is a modifed CalledMethodsChecker that checks that the must-call obligations of each expression (as computed via the MustCallChecker have been fulfilled.
  • 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:
  • Constructor Details

    • ResourceLeakChecker

      public ResourceLeakChecker()
      Creates a ResourceLeakChecker.
  • Method Details

    • getImmediateSubcheckerClasses

      protected Set<Class<? extends SourceChecker>> getImmediateSubcheckerClasses()
      Description copied from class: SourceChecker
      Returns the set of subchecker classes on which this checker depends. ("Depends" means the checkers that are subcheckers of the current checker rather than a subchecker of some other checker.) Returns an empty set if this checker does not depend on any others.

      If this checker should run multiple independent checkers and not contain a type system, then subclass AggregateChecker.

      Subclasses should override this method to specify subcheckers. If they do so, they should call the super implementation of this method and add dependencies to the returned set so that checkers required for reflection resolution are included if reflection resolution is requested.

      If a checker should be added or not based on a command line option, use SourceChecker.getOptionsNoSubcheckers() or SourceChecker.hasOptionNoSubcheckers(String) to avoid recursively calling this method.

      Each subchecker of this checker may also depend on other checkers. If this checker and one of its subcheckers both depend on a third checker, that checker will only be instantiated once.

      Though each checker is run on a whole compilation unit before the next checker is run, error and warning messages are collected and sorted based on the location in the source file before being printed. (See SourceChecker.printOrStoreMessage(Diagnostic.Kind, String, Tree, CompilationUnitTree).)

      WARNING: Circular dependencies are not supported. (In other words, if checker A depends on checker B, checker B cannot depend on checker A.) The Checker Framework does not check for circularity. Make sure no circular dependencies are created when overriding this method.

      This method is protected so it can be overridden, but it should only be called internally by SourceChecker.

      Overrides:
      getImmediateSubcheckerClasses in class CalledMethodsChecker
      Returns:
      the subchecker classes on which this checker depends; will be modified by callees
    • createSourceVisitor

      protected BaseTypeVisitor<?> createSourceVisitor()
      Description copied from class: BaseTypeChecker
      Returns the appropriate visitor that type-checks the compilation unit according to the type system rules.

      This implementation uses the checker naming convention to create the appropriate visitor. If no visitor is found, it returns an instance of BaseTypeVisitor. It reflectively invokes the constructor that accepts this checker and the 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:
      createSourceVisitor in class BaseTypeChecker
      Returns:
      the type-checking visitor
    • 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 CalledMethodsChecker
    • getIgnoredExceptions

      public SetOfTypes getIgnoredExceptions()
      Get 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