Skip to content

Don't use @Target({}) to prevent users from writing a type qualifier#7502

Merged
smillst merged 3 commits into
typetools:masterfrom
mernst:no-target-empty
Feb 25, 2026
Merged

Don't use @Target({}) to prevent users from writing a type qualifier#7502
smillst merged 3 commits into
typetools:masterfrom
mernst:no-target-empty

Conversation

@mernst

@mernst mernst commented Feb 23, 2026

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89e3e16 and 21840fe.

📒 Files selected for processing (1)
  • framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java

📝 Walkthrough

Walkthrough

Six qualifier annotations—FenumUnqualified, LockHeld, LockPossiblyHeld, SignatureUnknown, MaybeLeaked, and Unqualified—had their @Target changed from an empty set to {ElementType.TYPE_USE, ElementType.TYPE_PARAMETER} and now import java.lang.annotation.ElementType. AnnotatedTypeFactory.java received minor Javadoc and comment wording edits clarifying allowed qualifier targets and standardizing capitalization. No other public API or behavioral changes were introduced.

Suggested reviewers

  • smillst
🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java`:
- Line 23: Add the missing import for ElementType so the annotation usage
"@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})" compiles: add an
import for java.lang.annotation.ElementType near the other imports in the
FenumUnqualified file (referencing the ElementType symbol used in the class).

In
`@checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockHeld.java`:
- Line 22: The Target annotation on the LockHeld declaration references
ElementType but the import is missing; add the import for
java.lang.annotation.ElementType so the `@Target`({ElementType.TYPE_USE,
ElementType.TYPE_PARAMETER}) compiles—i.e., in the LockHeld source add an import
for ElementType alongside the existing annotation imports (the class/annotation
name to change is LockHeld and the annotation is `@Target`).

In
`@checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java`:
- Line 26: Add the missing import for ElementType used in the `@Target` annotation
of LockPossiblyHeld: add an import for java.lang.annotation.ElementType (or
import java.lang.annotation.*) at the top of the file so the annotation
`@Target`({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) compiles; update the
imports near the class declaration containing LockPossiblyHeld.

In
`@checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java`:
- Line 20: The annotation usage `@Target`({ElementType.TYPE_USE,
ElementType.TYPE_PARAMETER}) references java.lang.annotation.ElementType but the
import is missing; add the missing import (import
java.lang.annotation.ElementType;) to the SignatureUnknown.java file so the
`@Target` annotation compiles correctly alongside the existing `@Target` usage in
the SignatureUnknown declaration.

In
`@checker-qual/src/main/java/org/checkerframework/common/aliasing/qual/MaybeLeaked.java`:
- Line 24: The file MaybeLeaked.java uses ElementType in the `@Target` annotation
but does not import it; add the missing import for
java.lang.annotation.ElementType at the top of MaybeLeaked.java so the
annotation `@Target`({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) compiles
(ensure the existing Target import remains correct and do not remove any other
imports).

In
`@checker-qual/src/main/java/org/checkerframework/common/subtyping/qual/Unqualified.java`:
- Line 24: Add the missing import for ElementType in Unqualified.java: import
java.lang.annotation.ElementType; so the `@Target`({ElementType.TYPE_USE,
ElementType.TYPE_PARAMETER}) annotation resolves; update the imports at the top
of the file where other annotation imports (e.g., Target/Retention) are declared
to include ElementType.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82d7b38 and 730c9a6.

📒 Files selected for processing (7)
  • checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java
  • checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockHeld.java
  • checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java
  • checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java
  • checker-qual/src/main/java/org/checkerframework/common/aliasing/qual/MaybeLeaked.java
  • checker-qual/src/main/java/org/checkerframework/common/subtyping/qual/Unqualified.java
  • framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (6)
checker-qual/src/main/java/org/checkerframework/common/aliasing/qual/MaybeLeaked.java (1)

4-4: Missing ElementType import now added.

The previously flagged compilation error is resolved.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@checker-qual/src/main/java/org/checkerframework/common/aliasing/qual/MaybeLeaked.java`
at line 4, The compilation error was caused by a missing import for ElementType
used in the MaybeLeaked annotation; add the import statement "import
java.lang.annotation.ElementType;" to the top of the MaybeLeaked.java file
(where other imports are declared) so references to ElementType in the
annotation's `@Target` or related code resolve correctly.
checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java (1)

4-4: Missing ElementType import now added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java`
at line 4, There is a duplicate import of java.lang.annotation.ElementType in
LockPossiblyHeld.java; remove the extra import so the import block only contains
a single import java.lang.annotation.ElementType entry (ensure the file compiles
and no other duplicate imports remain).
checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockHeld.java (1)

4-4: Missing ElementType import now added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockHeld.java`
at line 4, The import for java.lang.annotation.ElementType in LockHeld.java
appears duplicated; remove the redundant import statement so only a single
import of ElementType remains (search for the import line referencing
ElementType in the LockHeld file and delete the duplicate).
checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java (1)

4-4: Missing ElementType import now added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java`
at line 4, The file now contains a redundant import of
java.lang.annotation.ElementType; open the FenumUnqualified class and remove the
duplicate import so there is only a single import statement for ElementType
(ensure the import for ElementType appears once and leave other imports
unchanged).
checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java (1)

4-4: Missing ElementType import now added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java`
at line 4, Remove the redundant import of java.lang.annotation.ElementType in
SignatureUnknown.java: ensure the file has at most one import for ElementType
(or remove it entirely if unused), clean up any duplicate or unused imports in
the SignatureUnknown class, and recompile to verify no unused-import warnings
remain.
checker-qual/src/main/java/org/checkerframework/common/subtyping/qual/Unqualified.java (1)

4-4: Missing ElementType import now added.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@checker-qual/src/main/java/org/checkerframework/common/subtyping/qual/Unqualified.java`
at line 4, Unqualified.java is missing the ElementType import; add the import
statement "import java.lang.annotation.ElementType;" to the top of the file so
any `@Target` or ElementType references compile (ensure it appears alongside
existing java.lang.annotation imports and there is no duplicate import), and
remove the stray "[duplicate_comment]" note from the review/diff metadata if it
was accidentally included.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java`:
- Line 24: The FenumUnqualified annotation's Javadoc forbids source use but
changing its `@Target` made that unenforceable; update the annotation declaration
for FenumUnqualified to include `@InvisibleQualifier` (and restore the restrictive
`@Target` if desired) so it cannot be written in source, or alternatively
implement checker-level rejection in the fenum checker (e.g., in the
type-annotation processing code that handles FenumUnqualified) to report an
error whenever FenumUnqualified appears in source; locate the annotation
declaration for FenumUnqualified and either add the `@InvisibleQualifier` marker
or add a validation hook in the checker code that rejects source occurrences.

In
`@checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java`:
- Line 21: The SignatureUnknown annotation currently allows source use (it has
`@Target`({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})) but lacks the
framework-level prevention used by other hidden qualifiers; add the
`@InvisibleQualifier` annotation to the SignatureUnknown declaration
(class/annotation SignatureUnknown) so it cannot be written in source code,
matching the pattern used by LockHeld, LockPossiblyHeld, MaybeLeaked, and
Unqualified and preserving the existing `@Target` settings.

---

Duplicate comments:
In
`@checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java`:
- Line 4: The file now contains a redundant import of
java.lang.annotation.ElementType; open the FenumUnqualified class and remove the
duplicate import so there is only a single import statement for ElementType
(ensure the import for ElementType appears once and leave other imports
unchanged).

In
`@checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockHeld.java`:
- Line 4: The import for java.lang.annotation.ElementType in LockHeld.java
appears duplicated; remove the redundant import statement so only a single
import of ElementType remains (search for the import line referencing
ElementType in the LockHeld file and delete the duplicate).

In
`@checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java`:
- Line 4: There is a duplicate import of java.lang.annotation.ElementType in
LockPossiblyHeld.java; remove the extra import so the import block only contains
a single import java.lang.annotation.ElementType entry (ensure the file compiles
and no other duplicate imports remain).

In
`@checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java`:
- Line 4: Remove the redundant import of java.lang.annotation.ElementType in
SignatureUnknown.java: ensure the file has at most one import for ElementType
(or remove it entirely if unused), clean up any duplicate or unused imports in
the SignatureUnknown class, and recompile to verify no unused-import warnings
remain.

In
`@checker-qual/src/main/java/org/checkerframework/common/aliasing/qual/MaybeLeaked.java`:
- Line 4: The compilation error was caused by a missing import for ElementType
used in the MaybeLeaked annotation; add the import statement "import
java.lang.annotation.ElementType;" to the top of the MaybeLeaked.java file
(where other imports are declared) so references to ElementType in the
annotation's `@Target` or related code resolve correctly.

In
`@checker-qual/src/main/java/org/checkerframework/common/subtyping/qual/Unqualified.java`:
- Line 4: Unqualified.java is missing the ElementType import; add the import
statement "import java.lang.annotation.ElementType;" to the top of the file so
any `@Target` or ElementType references compile (ensure it appears alongside
existing java.lang.annotation imports and there is no duplicate import), and
remove the stray "[duplicate_comment]" note from the review/diff metadata if it
was accidentally included.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 730c9a6 and 89e3e16.

📒 Files selected for processing (6)
  • checker-qual/src/main/java/org/checkerframework/checker/fenum/qual/FenumUnqualified.java
  • checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockHeld.java
  • checker-qual/src/main/java/org/checkerframework/checker/lock/qual/LockPossiblyHeld.java
  • checker-qual/src/main/java/org/checkerframework/checker/signature/qual/SignatureUnknown.java
  • checker-qual/src/main/java/org/checkerframework/common/aliasing/qual/MaybeLeaked.java
  • checker-qual/src/main/java/org/checkerframework/common/subtyping/qual/Unqualified.java

@smillst smillst merged commit 146dd82 into typetools:master Feb 25, 2026
21 checks passed
@smillst smillst deleted the no-target-empty branch February 25, 2026 17:18
@coderabbitai coderabbitai Bot mentioned this pull request Jul 5, 2026
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.

2 participants