Skip to content

Reduce reliance on KType.isMarkedNullable - #273

Merged
freya022 merged 5 commits into
3.Xfrom
refactor/nullability-checks
Aug 25, 2026
Merged

Reduce reliance on KType.isMarkedNullable#273
freya022 merged 5 commits into
3.Xfrom
refactor/nullability-checks

Conversation

@freya022

Copy link
Copy Markdown
Owner

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-reflect on failures. This is the case for the BotCommands-typesafe-messages module.

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
freya022 force-pushed the refactor/nullability-checks branch 2 times, most recently from 927e79f to 9f4c056 Compare August 24, 2026 14:32
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
freya022 force-pushed the refactor/nullability-checks branch from 9f4c056 to f95404e Compare August 24, 2026 15:30
@freya022
freya022 merged commit 0427b1b into 3.X Aug 25, 2026
1 check passed
@freya022
freya022 deleted the refactor/nullability-checks branch August 25, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant