Skip to content

SuppressWarningsWithoutExplanation Inconsistency Between Documentation and Implementation #5218

@ryanpinter

Description

@ryanpinter

There is an inconsistency between the documentation and the actual implementation of the SuppressWarningsWithoutExplanation bug checker in Error Prone.

Description

  1. The main documentation at https://errorprone.info/bugpattern/SuppressWarningsWithoutExplanation states the following:

    • In the "Introduction / One line summary" section: "Use of @SuppressWarnings should be accompanied by a comment describing why the warning is safe to ignore."
      • This implies ALL @SuppressWarnings
    • In the "The problem" section: "Suppressions for unchecked or rawtypes warnings should have an accompanying comment..."
      • This implies this check is only applicable to @SuppressWarnings for unchecked and rawtypes
  2. The actual code implementation at SuppressWarningsWithoutExplanation.java:

    • Code comment states: "The Google style guide mandates this for all suppressions; this is only matching on {@code deprecation} as a trial."
    • Implementation only checks for "deprecation" suppressions as shown in:
      private static final Matcher<AnnotationTree> SUPPRESS_WARNINGS =
          allOf(
              isSameType(SuppressWarnings.class),
              hasArgumentWithValue("value", stringLiteral("deprecation")));

Expected Behavior

Based on the Google style guide referenced in the code (which mandates explanatory comments for all suppressions) and the general documentation, this check should apply to ALL @SuppressWarnings annotations, not just those with "deprecation" value.

Suggested Fix

  1. Update the implementation to check all @SuppressWarnings annotations
  2. Or update the implementation to check only @SuppressWarnings for unchecked or rawtypes
  3. Or update the documentation to clearly state that this check currently only applies to "deprecation" suppressions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions