Skip to content

8344159: Add lint warnings for unnecessary warning suppression #24882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 70 commits into from

Conversation

archiecobbs
Copy link
Contributor

@archiecobbs archiecobbs commented Apr 25, 2025

This PR adds support for warning about @SuppressWarnings annotations and -Xlint:-foo flags that are unnecessary because they don't actually suppress any warnings.

The change is a new requirement to ensure that all warning suppression is "validated". That means knowing when any warning that is currently being suppressed would have been generated had it not been suppressed. This requirement is satisfied automatically in most cases - i.e., when log.warning() to log a warning without explicit manipulation of the current Lint instance. Other cases have been updated to ensure proper validation.

The new warning reveals hundreds of unnecessary suppressions in the JDK which are spread all over the place, and there is a steady trickle of new ones being added all the time. Instead of trying to patch both the compiler and hundreds of Java source files all at once, this PR just disables the new lint categories in those components that would otherwise fail to build with -Werror. Those unnecessary suppressions can then be addressed separately per-component over time.

Summary of changes:

  • New lint category suppression warns about recognized @SuppressWarnings values that don't actually suppress any warnings
  • New lint category suppression-option warns about -Xlint:foo flags that don't actually suppress any warnings (also requires options)
  • The method Log.warning() now also automatically validates the current suppression of the lint category, if any
  • New method Lint.isActive() tests whether a category is enabled or suppression of the category still needs validation
  • New boolean flag validate is added to Lint.isEnabled() and Lint.isSuppressed() to optionally also validate any current suppression
  • The singleton LintMapper now also keeps track of which suppressions are validated and (later) warns about those that never are

Dependencies:


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8356043 to be approved

Warning

 ⚠️ Found leading lowercase letter in issue title for 6723459: javac to flag where warning suppression is not required

Issues

  • JDK-8344159: Add lint warnings for unnecessary warning suppression (Enhancement - P4)
  • JDK-6723459: javac to flag where warning suppression is not required (Enhancement - P3)
  • JDK-8356043: Add lint warnings for unnecessary warning suppression (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24882/head:pull/24882
$ git checkout pull/24882

Update a local copy of the PR:
$ git checkout pull/24882
$ git pull https://git.openjdk.org/jdk.git pull/24882/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24882

View PR using the GUI difftool:
$ git pr show -t 24882

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24882.diff

@archiecobbs
Copy link
Contributor Author

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label May 1, 2025
@openjdk
Copy link

openjdk bot commented May 1, 2025

@archiecobbs has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@archiecobbs please create a CSR request, with the correct fix version, for at least one of the issues associated with this pull request. This pull request cannot be integrated until all the CSR request are approved.

@openjdk
Copy link

openjdk bot commented May 1, 2025

@archiecobbs this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8348611+suppression
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label May 1, 2025
@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch and removed merge-conflict Pull request has merge conflict with target branch labels May 1, 2025
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label May 5, 2025
@archiecobbs
Copy link
Contributor Author

Closing - obsoleted by #25167

@archiecobbs archiecobbs deleted the JDK-8348611+suppression branch June 2, 2025 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build build-dev@openjdk.org client client-libs-dev@openjdk.org compiler compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org csr Pull request needs approved CSR before integration hotspot-jfr hotspot-jfr-dev@openjdk.org kulla kulla-dev@openjdk.org serviceability serviceability-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

1 participant