Skip to content

Introduce @UnannnotatedFor - #856

Draft
aosen-xiong wants to merge 16 commits into
eisop:masterfrom
aosen-xiong:jspecify-eisop
Draft

Introduce @UnannnotatedFor#856
aosen-xiong wants to merge 16 commits into
eisop:masterfrom
aosen-xiong:jspecify-eisop

Conversation

@aosen-xiong

@aosen-xiong aosen-xiong commented Aug 15, 2024

Copy link
Copy Markdown
Collaborator

Fixes #1292.

Do it after #1996, we would likely need the same subpackage instrumentation.

@aosen-xiong aosen-xiong changed the title JSpecify - eisop nullness checker Introduce @UnAnnnotatedFor Jun 28, 2025
@aosen-xiong aosen-xiong changed the title Introduce @UnAnnnotatedFor Introduce @UnannnotatedFor Jun 28, 2025
@aosen-xiong

Copy link
Copy Markdown
Collaborator Author

TODO: change Retention for both annotatedfor and unannotatedfor qualifiers.

aosen-xiong and others added 4 commits October 12, 2025 12:48
Keep only the introduction of @UnannotatedFor.  Conflicts between
@AnnotatedFor and @UnannotatedFor on the same element are left for a separate
change, so drop what this branch had toward them:

 * SourceChecker: revert to master.  Its only effect was to let an
   @UnannotatedFor override an @AnnotatedFor on the same element; for every
   other element it returned what master already returned, and no test covers
   it.  It also declared an unused ANNOTATEDFOR_CONFLICT message key with no
   entry in any messages.properties, and iterated both annotation arrays after
   a null check that only required one of them to be non-null.

 * QualifierDefaults: remove a commented-out copy of
   isElementUnannotatedForThisChecker and restore a Javadoc typo.

The only merge conflict was an import in AnnotatedTypeFactory.
Conflict in QualifierDefaults: eisop#1331 removed isElementAnnotatedForThisChecker
and its elementAnnotatedFors cache from QualifierDefaults, so this branch's
changes to that method are obsolete.  Take master's side; the @UnannotatedFor
logic is ported to the shared lookup in a follow-up commit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…or scope

@UnannotatedFor was defined and given an AnnotatedTypeFactory helper, but its
effect was implemented in QualifierDefaults.isElementAnnotatedForThisChecker,
which eisop#1331 removed.  Implement it in the lookup that replaced it,
BaseTypeChecker.isElementAnnotatedForThisCheckerOrUpstreamChecker, so that it
governs both conservative defaults and warning suppression.

@AnnotatedFor is tested first, so @UnannotatedFor is purely subtractive: it
stops the walk to the enclosing element, and never overrides an explicit
@AnnotatedFor on the same element.  A nested @AnnotatedFor takes effect again.

Both shouldSuppressWarnings overloads accumulated the @AnnotatedFor answer over
every enclosing declaration, and the TreePath overload additionally asked about
the enclosing package.  That defeated the exclusion: an @UnannotatedFor class in
an @AnnotatedFor package was defaulted as unchecked code but still had its
warnings reported.  Ask isElementAnnotatedForThisCheckerOrUpstreamChecker once,
about the innermost declaration; it already resolves enclosing scopes, so the
per-level query was redundant work even before this change.

Only one cache is needed.  The element's cached boolean is the fully-resolved
scope answer, including @UnannotatedFor exclusions.

Also mirror doesUnannotatedForApplyToThisChecker on its @AnnotatedFor sibling,
and correct the @UnannotatedFor javadoc, which claimed an effect on bytecode
although the annotation has source retention.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

Add UnAnnotatedFor to simulate NullUnmarked annotation

1 participant