Skip to content

Move @AnnotatedFor check to BaseTypeChecker#24

Merged
aosen-xiong merged 2 commits into
aosen-xiong:code-refactor-annotatedforfrom
thisisalexandercook:stub-file-fix
Apr 30, 2026
Merged

Move @AnnotatedFor check to BaseTypeChecker#24
aosen-xiong merged 2 commits into
aosen-xiong:code-refactor-annotatedforfrom
thisisalexandercook:stub-file-fix

Conversation

@thisisalexandercook

@thisisalexandercook thisisalexandercook commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

This is a follow-up to the @AnnotatedFor refactor in eisop#1331. It keeps the shared @AnnotatedFor scope computation, but moves ownership of the recursive/cached scope check out of AnnotatedTypeFactory and into BaseTypeChecker.

This was previously blocked by QualifierDefaults calling into BaseTypeChecker before normal checker/type-factory initialization was complete, as discussed here. The concrete failure path comes from stub/ajava parsing during type factory postInit():

GenericAnnotatedTypeFactory.postInit()
  -> parseAnnotationFiles()
  -> stub/ajava parser asks the type factory for a defaulted type
  -> QualifierDefaults.annotate(...)
  -> QualifierDefaults.applyConservativeDefaults(...)
  -> checker.isElementAnnotatedForThisCheckerOrUpstreamChecker(...)
  -> BaseTypeChecker.getTypeFactory()

At that point, routing through the checker can cause an NPE because getTypeFactory() depends on the visitor, which is not available yet.

This PR avoids that by skipping conservative unchecked-code @AnnotatedFor lookup while stub/ajava parsing is active. This does not change the existing policy for stub-file elements: QualifierDefaults currently treats stub files as checked code, see comment here. That existing block handles elements after they are known to come from parsed stub files. The new guard handles the earlier phase where annotation-file metadata is still being parsed.

Most stubs, including annotated-JDK class stubs, are only indexed during initialization and parsed lazily later, when an annotation lookup reaches that JDK class. The risky cases are the annotation files parsed eagerly during postInit(), such as checker @StubFiles, command-line stubs, ajava files, and annotated-JDK package-info.java files.

@aosen-xiong aosen-xiong left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@aosen-xiong aosen-xiong merged commit e91b31e into aosen-xiong:code-refactor-annotatedfor Apr 30, 2026
50 checks passed
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