Skip to content

fix: expose raw typed annotation lookup - #3092

Open
mvanhorn wants to merge 1 commit into
google:mainfrom
mvanhorn:fix/1038-bug-classnotfoundexception-but-it-does-exist-in
Open

fix: expose raw typed annotation lookup#3092
mvanhorn wants to merge 1 commit into
google:mainfrom
mvanhorn:fix/1038-bug-classnotfoundexception-but-it-does-exist-in

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Add an experimental getKSAnnotationsByType() utility that reuses the existing short-name and qualified-name matching logic while returning Sequence<KSAnnotation> without constructing annotation proxies. KSAnnotated.getAnnotationsByType() still converts every matching KSAnnotation into a runtime annotation proxy.

A source annotation with one KClass member and an array of KClass members is found through getKSAnnotationsByType(), and the processor reads the expected qualified names from the raw KSType argument values without throwing; Built-in, source-declared, array, and generic array class literals remain distinguishable through the raw values, while the existing typed lookup continues to match the same annotation and retain its established proxy behavior.

Fixes #1038

@jaschdoc

Copy link
Copy Markdown
Collaborator

Hi @mvanhorn, thanks for the PR! Could you add a test for this first in a separate PR? See https://github.com/google/ksp/blob/main/CONTRIBUTING.md for more information :)

@mvanhorn

mvanhorn commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Done, split out as #3108.

That PR is tests only, no production code, and the EXPECTED block records what KSP does today rather than what I want it to do, so the behaviour change shows up as a diff in that file when this PR lands on top.

It covers the two things around the existing case that were untested:

  • isAnnotationPresent on the annotation whose KClass values are not loadable
  • a second annotation nested in a private object that shares the simple name ClassValueAnnotation but not the qualified name, asserted through both getAnnotationsByType(...).count() and isAnnotationPresent(...), which pins the lookup to qualified-name matching

Current behaviour, now recorded:

User
String, Company, IntArray, Array<User>
true
0
false

Both AAConfiguredUnitTestSuite and PsiConfiguredUnitTestSuite pass on unmodified upstream code.

I'll rebase this PR on #3108 once it lands so the diff here is just the behaviour change plus the two new expected lines.

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.

Bug: ClassNotFoundException, but it does exist in the project

2 participants