Interface DiagnosticSink

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface DiagnosticSink
A destination for Checker Framework diagnostics, allowing a host to intercept findings instead of having them printed through javac's Trees.

By default a SourceChecker reports each finding directly to javac. A host that embeds the Checker Framework can install a DiagnosticSink (see SourceChecker.setDiagnosticSink(org.checkerframework.framework.source.DiagnosticSink)) to receive findings and report them through its own channel instead. This is used when the Checker Framework runs as an Error Prone plugin, so that Checker Framework findings become Error Prone Descriptions (honoring Error Prone severity, suppression, and the suggested-fix / patch pipeline).

Only findings positioned at a Tree reach the sink. A finding positioned at an Element (rather than a tree), or with no source position at all, is still reported directly through javac's Messager, because such a finding has no Tree/TreePath for a host to anchor its own diagnostic to. In Error Prone mode those (rare) findings therefore appear as plain javac diagnostics rather than host diagnostics. Almost all Checker Framework findings are positioned at a tree.

This interface intentionally uses only javax.tools, com.sun.source.tree, and Checker Framework types, so the Checker Framework core has no dependency on any host framework (in particular, no dependency on Error Prone). The translation from these neutral values to a host-specific representation is the host's responsibility.

  • Method Details

    • report

      void report(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root, @Nullable TreePath path, List<SuggestedFixData> fixes)
      Receives one Checker Framework finding, which may carry machine-applicable suggested fixes (as alternatives). A host with no fix pipeline simply ignores fixes, so this interface can be implemented with a lambda.
      Parameters:
      kind - the diagnostic kind (typically Diagnostic.Kind.ERROR or Diagnostic.Kind.WARNING)
      message - the fully-formatted, localized message text
      source - the tree at which the finding is reported; its source position locates the diagnostic. Never null: a finding with no tree position is reported through javac before reaching a sink (see above), so an installed sink is called only for tree-positioned findings.
      root - the compilation unit containing source
      path - the path to source, or null if it could not be determined. The checker computes it while visiting the finding, which is far cheaper than a host re-deriving it afterwards: by the time findings are handed over, locating a tree costs a scan of the whole compilation unit, so re-deriving it per finding is quadratic in the number of findings in a file.
      fixes - suggested fixes for the finding, as alternatives (possibly empty)