Skip to content

Add test for @SuppressWarnings and @AnnotatedFor interaction and refine SourceChecker logic - #1699

Merged
wmdietl merged 26 commits into
eisop:masterfrom
aosen-xiong:fix-annotatedfor-warning
Aug 27, 2026
Merged

Add test for @SuppressWarnings and @AnnotatedFor interaction and refine SourceChecker logic#1699
wmdietl merged 26 commits into
eisop:masterfrom
aosen-xiong:fix-annotatedfor-warning

Conversation

@aosen-xiong

Copy link
Copy Markdown
Collaborator

Fix @SuppressWarnings on an enclosing element being ignored when an inner element carries @AnnotatedFor.

The early return was redundant: the loop's natural termination already produces false when no matching @SuppressWarnings is found. Removing it lets the walk continue past @AnnotatedFor-annotated elements to enclosing scopes.

Copilot AI review requested due to automatic review settings May 5, 2026 02:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes warning suppression behavior in SourceChecker so an enclosing @SuppressWarnings still applies when an inner declaration is marked @AnnotatedFor. It also adds regression tests in both framework-level subtyping tests and nullness conservative-default tests.

Changes:

  • Removed the redundant early return in SourceChecker.shouldSuppressWarnings(Element, String) so suppression lookup continues through enclosing elements.
  • Added a subtyping regression test covering class-level @SuppressWarnings with a method-level @AnnotatedFor.
  • Added a nullness regression test covering the same interaction for nullness checking.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
framework/tests/conservative-defaults/annotatedfor/AnnotatedForTest.java Adds a regression case proving outer @SuppressWarnings("subtyping") overrides inner @AnnotatedFor("subtyping").
framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java Removes the early exit that prevented suppression lookup from reaching enclosing scopes.
checker/tests/nulless-conservative-defaults/annotatedfornullness/AnnotatedForNullness.java Adds a nullness regression case for the same suppression/@AnnotatedFor interaction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thisisalexandercook thisisalexandercook left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! It may be worth noting that #1331 also removes this check as part of its broader refactor, but this bug is independent and makes sense as its own PR.

Comment thread framework/tests/conservative-defaults/annotatedfor/AnnotatedForTest.java Outdated
Co-authored-by: Alex Cook <43047600+thisisalexandercook@users.noreply.github.com>
@aosen-xiong

Copy link
Copy Markdown
Collaborator Author

Great catch! It may be worth noting that #1331 also removes this check as part of its broader refactor, but this bug is independent and makes sense as its own PR.

Thanks! Yes, that's the point of having this PR.

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!
Also, please go through the javadoc and manual and see where this behavior is described.

@aosen-xiong
aosen-xiong requested a review from wmdietl May 14, 2026 03:19
@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong May 14, 2026

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some high-level clarifications that I need to understand what this is trying to do.

Comment thread docs/manual/annotating-libraries.tex Outdated
Comment thread docs/manual/warnings.tex Outdated
Comment thread framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java Outdated
@wmdietl wmdietl assigned aosen-xiong and unassigned wmdietl Jun 8, 2026
@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong Jun 19, 2026
@wmdietl

wmdietl commented Jul 17, 2026

Copy link
Copy Markdown
Member

@aosen-xiong Please review what I did with Antigravity.

@wmdietl wmdietl assigned aosen-xiong and unassigned wmdietl Jul 17, 2026
@aosen-xiong

Copy link
Copy Markdown
Collaborator Author

@aosen-xiong Please review what I did with Antigravity.

Thanks! Your changes make the Element and TreePath overloads consistent.

@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong Jul 17, 2026
@aosen-xiong

Copy link
Copy Markdown
Collaborator Author

@wmdietl pin for review.

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@wmdietl
wmdietl enabled auto-merge (squash) August 27, 2026 21:41
@wmdietl
wmdietl merged commit 158515a into eisop:master Aug 27, 2026
44 checks passed
@aosen-xiong
aosen-xiong deleted the fix-annotatedfor-warning branch August 27, 2026 22:30
aosen-xiong added a commit to aosen-xiong/checker-framework that referenced this pull request Aug 28, 2026
Three conflicts, all from eisop#1699, which refined the same @AnnotatedFor and
@SuppressWarnings logic this branch refactors.

SourceChecker: kept master's post-eisop#1699 control flow -- the foundAnnotatedFor
accumulation and hasSuppressWarningsAnnotationForErrorKey -- and applied only
this branch's change on top: rename isAnnotatedForThisCheckerOrUpstreamChecker
to isElementAnnotatedForThisCheckerOrUpstreamChecker and make it abstract,
implemented in BaseTypeChecker.  This branch had returned false as soon as an
@AnnotatedFor element was found; eisop#1699 deliberately keeps scanning so that a
@SuppressWarnings on an enclosing declaration still wins, which is what its
new ElementSuppressionTest pins.  The redundant packageElement call this
branch deleted is kept, since it sits inside that logic.

AnnotatedTypeFactory: both sides added the same method under different names.
Took master's isParsingAnnotationFile() and its Javadoc, and updated this
branch's caller in QualifierDefaults.

QualifierDefaults: the relocated isElementAnnotatedForThisChecker stays
removed, and this branch's annotation-file-parsing guard is kept, without the
TODO comment that master deleted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants