Class InitializationFieldAccessSubchecker

All Implemented Interfaces:
Processor, OptionConfiguration

@SupportedOptions("assumeInitialized") public class InitializationFieldAccessSubchecker extends BaseTypeChecker
Part of the freedom-before-commitment type system.

This checker does not actually do any type checking. It exists to provide its parent checker (the InitializationChecker.getTargetCheckerClass()) with declared initialization qualifiers via the InitializationFieldAccessTreeAnnotator.

Additionally, this checker performs the flow-sensitive type refinement for the fbc type system, which is necessary to avoid reporting follow-up errors related to initialization (see the AssignmentDuringInitialization test case). To avoid performing the same type refinement twice, the InitializationChecker performs no refinement, instead reusing the results from this checker.

See Also:
  • Constructor Details

    • InitializationFieldAccessSubchecker

      public InitializationFieldAccessSubchecker()
      Default constructor for InitializationFieldAccessSubchecker.
  • Method Details

    • addOptionsForMode

      protected void addOptionsForMode(String mode, Map<String,String> activeOptions)
      Description copied from class: SourceChecker
      Adds to activeOptions the options that mode enables for this checker. The default implementation adds none; a checker that declares modes with SupportedModes overrides this, calls super, and ignores a mode it does not recognize (another checker in the same run may define it).

      Use Map.putIfAbsent(K, V): activeOptions already holds the options written on the command line, which take precedence over the mode.

      Overrides:
      addOptionsForMode in class SourceChecker
      Parameters:
      mode - the value of the -Amode option
      activeOptions - the active options, to which mode options are added
    • getUpstreamCheckerNames

      public List<@FullyQualifiedName String> getUpstreamCheckerNames()
      Also handle AnnotatedFor annotations for the InitializationChecker. See InitializationChecker.getUpstreamCheckerNames() and the two implementations should be kept in sync.
      Overrides:
      getUpstreamCheckerNames in class SourceChecker
      Returns:
      a list containing this checker name and all checkers it is a part of (that is, checkers that called it)
      See Also:
    • 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.

      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:
      reportError in class SourceChecker
      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 key
      args - arguments for interpolation in the string corresponding to the given message key
    • reportWarning

      public void reportWarning(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args)
      Description copied from class: SourceChecker
      Reports a warning. 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:
      reportWarning in class SourceChecker
      Parameters:
      source - the source position information; may be an Element or a Tree. Null means the warning has no source position -- for example, it is issued while the checker is initializing, before any source file is processed. Such a warning cannot be suppressed by a @SuppressWarnings annotation, because there is no declaration to write one on; only the -AsuppressWarnings command-line option suppresses it.
      messageKey - the message key
      args - arguments for interpolation in the string corresponding to the given message key