Reduce reliance on KType.isMarkedNullable - #273
Merged
Conversation
The new K2 impl from kotlin-reflect 2.4+ always reports Java types to be non-null regardless of runtime annotations Whether this is intentional or not, we now always read our own metadata from both class and runtime-retained annotations
freya022
force-pushed
the
refactor/nullability-checks
branch
2 times, most recently
from
August 24, 2026 14:32
927e79f to
9f4c056
Compare
At this point in the code, we don't have access to reflection metadata, so kotlin-reflect must be used. However, kotlin-reflect is unreliable in some cases, and would never be able to read class-retained (invisible) annotations. This new way allows us to read type-use and parameter annotations, visible or not.
…bility Avoids computing types for potentially non-null parameters Our metadata already has more/equally accurate nullabilities, kotlin-reflect would be more accurate only for private functions, which we don't process.
freya022
force-pushed
the
refactor/nullability-checks
branch
from
August 24, 2026 15:30
9f4c056 to
f95404e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors most places to avoid using
KType.isMarkedNullable, starting Kotlin 2.4, some types could return an incorrect value as the new K2 implementation doesn't try to find nullable runtime annotations. (see KT-88503)We now almost exclusively fetch nullabilities from the reflection metadata, meaning type-use and parameter annotations, runtime or class-retained, are taken into account.
In places where the metadata is not yet available, the class's binary is read on-demand to provide the same functionality, falling back to
kotlin-reflecton failures. This is the case for theBotCommands-typesafe-messagesmodule.