Skip to content

Use top as the qualifier upper bound in a hierarchy that has no bound - #8639

Open
mernst wants to merge 6 commits into
typetools:masterfrom
mernst:limit-to-bound-missing-bound
Open

mernst wants to merge 6 commits into
typetools:masterfrom
mernst:limit-to-bound-missing-bound

Conversation

@mernst

@mernst mernst commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Land before #8667.

A checker can override AnnotatedTypeFactory.getDefaultTypeDeclarationBounds() to return qualifiers in only some of its type hierarchies. Then QualifierUpperBounds.getBoundQualifiers() returned no bound in the other hierarchies, and the Checker Framework crashed:

This pull request makes getBoundQualifiers use top as the bound in a hierarchy in which no bound is specified (by an annotation on the type's declaration, by @UpperBoundFor, or by getDefaultTypeDeclarationBounds()). Top is also the bound that the default implementation of getDefaultTypeDeclarationBounds() returns, so a missing qualifier means "no restriction". Now every caller of getBoundQualifiers and getTypeDeclarationBounds gets exactly one bound in each hierarchy, and none of them needs a special case. The Javadoc of getDefaultTypeDeclarationBounds and getTypeDeclarationBounds documents that.

This pull request also changes which errors such a checker reports, not just whether it crashes. BaseTypeVisitor.checkExtendsOrImplements used to skip a hierarchy that had no bound. Now it compares top to the supertype's qualifier. As a result, a checker that overrides getDefaultTypeDeclarationBounds() to return a partial set (and that did not crash, for example because it overrides isValidUse) can now report declaration.inconsistent.with.extends.clause or declaration.inconsistent.with.implements.clause for a class declaration such as class Sub extends @H2S1 Super {}. The test class UsesWithoutBound.NoBoundSub2 shows this.

The new test checker PartialBoundsH1H2Checker is the H1H2Checker with getDefaultTypeDeclarationBounds() returning only @H1S1, which is also its default qualifier in the H1 hierarchy. Because that bound is not top, the tests also check that the default bound is enforced in the H1 hierarchy. Its tests in framework/tests/h1h2checker-partial-bounds/ exercise casts, array initializers, uses of types in fields, parameters, locals, arrays, primitives, and type arguments, new (including anonymous classes), getClass(), extends and implements clauses, enums, and declarations with explicit H1 or H2 bounds. Without the fix, both test files crash.

…at has no bound

The new test still crashes, in BaseTypeVisitor.isValidUse.
Revert the limitToBound change; getBoundQualifiers now returns a bound in every hierarchy, so its callers, such as limitToBound and BaseTypeVisitor.isValidUse, need no special case.
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

getBoundQualifiers now adds each qualifier hierarchy’s top annotation after applying default type-declaration bounds. The documentation describes the returned bounds and the default for an omitted hierarchy. A test checker supplies an H1 bound without an H2 bound, and new directory tests cover uses of unbounded and explicitly bounded declarations.

Possibly related PRs

  • typetools/checker-framework#8667: Changes related bound-selection behavior in limitToBound and BaseTypeVisitor.isValidUse, and shares the bound-selection contract addressed here.

Change: Bug fix

Merge Risk: Minimal · up to 6b1bd

This change makes type-declaration bounds fall back to the top qualifier in any hierarchy that has no bound, which avoids crashes in cast, array-initializer and use-validity paths. The change is small and covered by new directory tests. No concrete merge-blocking risk was found. One possible issue with getClass() was not confirmed.

Pre-merge checks: Passed 2

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 78ff53e and 6b1bde5.

Files selected for processing: 2

  • framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java
  • framework/src/main/java/org/checkerframework/framework/type/QualifierUpperBounds.java

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

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