Skip to content

[Byecode] Hide internal Kotlin fields marked with @JvmField. #1004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2022

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Jul 5, 2022

Fixes #954

Internal Kotlin fields that are marked with @JvmField are exposed as public in the compiled bytecode so they can be consumed by Java.

// Kotlin
@JvmField
internal val city: String = "London"
// Java
@JvmField
@NotNull
public final String city = "London";

This is a bit of a conundrum because internal means "can't be consumed by other libraries" and @JvmField means "make this consumable by other Java libraries". 🤷‍♂️

This can cause issues for binding, as the type of those fields may be internal, and thus our binding process will not find the type.

Let's honor the original internal visibility to produce consistent bindings. (kotlin-internal can be overridden with generator metadata if desired.)

We need to examine the encoded Kotlin metadata to determine if the field should be marked as kotlin-internal the same way we do with methods and properties.

@jpobst jpobst marked this pull request as ready for review July 5, 2022 17:08
@jonpryor jonpryor merged commit b7caa78 into main Jul 7, 2022
@jonpryor jonpryor deleted the internal-kotlin-fields branch July 7, 2022 01:20
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kotlin @JvmField internal fields not being removed
2 participants