Class DetectorDefaultSeverity

java.lang.Object
se.deversity.asynctest.diagnostics.DetectorDefaultSeverity

@API(status=EXPERIMENTAL) public final class DetectorDefaultSeverity extends Object
The severity a detector's findings carry when its own report does not say.

Why this exists. IssueSeverity.fromReport(String) recovers a finding's severity by matching markers in the report text, and returned IssueSeverity.HIGH when it found none. 86 of the 142 built-in detectors write no marker, so a merge gate on failOn = HIGH failed on all of them alike: a spin loop that should yield, an explicit System.gc() and a lost update were ranked identically, because none of the three said anything and the default said HIGH. That made failOn = HIGH close to "fail on anything", which is the same as no gate at all.

From 1.9.7 every one of those detectors stated its severity here, chosen against IssueSeverity's own definitions: CRITICAL where the report's primary claim is that something will not make progress, HIGH where it claims corruption or an incorrect result, MEDIUM for degradation and leaks, LOW for an inefficiency. Where two readings were defensible the higher was taken, because under-ranking a real bug costs more than over-ranking a benign one.

A detector's own report always wins. This table is consulted only when the report carries no structured severity (see structuredIn(java.lang.Object)) and its text marks none, so a detector that learns to state one per finding overrides it without touching this file, and its entry then has to be removed: DetectorSeverityMarkerTest fails on an entry for a detector that marks its own reports, so the table can only shrink as the detectors improve.

The table is empty. Since #801 every built-in detector keeps its findings as Violations at the severity its text used to resolve to, so none falls back to an entry here; the structured severities are the ones this table, or a marker, gave them. of(DetectorType) stays for callers and yields empty for every type; a detector added without a structured severity of its own still fails DetectorSeverityMarkerTest unless it marks its text or regains an entry.

Third-party detectors arriving through the SPI are not in this table and keep the historical HIGH default. The library has no basis for ranking somebody else's finding.

Since:
1.9.7
  • Field Details

  • Method Details

    • of

      public static Optional<IssueSeverity> of(DetectorType type)
      Returns the declared severity for a built-in detector that marks none itself, if any.
      Parameters:
      type - the detector; null yields empty
      Returns:
      the declared severity for a built-in detector that marks none itself, if any
    • of

      public static IssueSeverity of(String detectorName, String report)
      Returns the severity a finding should be gated on, from its text alone.

      Precedence: what the report text marks, then what the detector declares here, then IssueSeverity.HIGH for anything this library does not know, which is every third-party detector. Callers that hold the report object use of(String, String, IssueSeverity) with structuredIn(java.lang.Object), which the text cannot override.

      Parameters:
      detectorName - the reporting detector's name, as it appears in the report map
      report - the report text
      Returns:
      the severity a finding should be gated on, from its text alone
    • of

      @API(status=EXPERIMENTAL) public static IssueSeverity of(String detectorName, String report, @Nullable IssueSeverity structured)
      Returns the severity a finding should be gated on.

      The one place that answer is computed, so the failOn gate, the JSON report and the SARIF output cannot disagree about what a finding was worth. Precedence: the severity the detector put in its structured findings, then of(String, String).

      The structured severity comes first because it is the one the detector chose per finding. Text matching only guesses: ThreadLocalCacheDegradationDetector rates every finding MEDIUM in its Violation, writes no marker, and has no entry here, so the text route alone reached the HIGH fallback and failed a failOn = HIGH build.

      Parameters:
      detectorName - the reporting detector's name, as it appears in the report map
      report - the report text
      structured - the most severe structured severity of this report, or null
      Returns:
      the severity a finding should be gated on
      Since:
      1.12.3
    • structuredIn

      @API(status=EXPERIMENTAL) public static Optional<IssueSeverity> structuredIn(@Nullable Object report)
      Returns the most severe severity among a report's structured findings, when it keeps any.

      Built-in reports that hold their findings as Violations beside the text expose them in a public List<Violation> structuredViolations field. There is no shared interface for it, so the field is read by name, the way the SPI bridge read analyze() until 1.13.0. A report without the field, or with an empty list, yields empty and the caller falls back to the text. DetectorSeverityMarkerTest relies on the same field name to decide which detectors state their own severity.

      Parameters:
      report - a detector's report object; null yields empty
      Returns:
      the most severe severity among a report's structured findings, when it keeps any
      Since:
      1.12.3
    • structuredFindingsIn

      @API(status=EXPERIMENTAL) public static List<Violation> structuredFindingsIn(@Nullable Object report)
      Returns a report's structured findings, in its order; empty when it keeps none.

      Read from the same structuredViolations field as structuredIn(java.lang.Object). The runner's one-line summary of a folded block counts and heads with these, because a report's text also lists context and advice as bullets, and counting those read advice as a finding (#773).

      Parameters:
      report - a detector's report object; null yields empty
      Returns:
      a report's structured findings, in its order; empty when it keeps none
      Since:
      1.12.4