Skip to content

Fix J2KT build error for @Memoized methods returning reference types.#2045

Merged
copybara-service[bot] merged 1 commit intomainfrom
test_903880894
Apr 27, 2026
Merged

Fix J2KT build error for @Memoized methods returning reference types.#2045
copybara-service[bot] merged 1 commit intomainfrom
test_903880894

Conversation

@copybara-service
Copy link
Copy Markdown
Contributor

Fix J2KT build error for @memoized methods returning reference types.

J2KT requires non-nullable Kotlin properties to be initialized. For @memoized methods returning reference types, AutoValue generates fields without initialization, relying on Java's default null initialization. If these fields are not marked @nullable in Java, J2KT generates non-nullable Kotlin properties, leading to compilation errors like "property must be initialized or be abstract".

This change ensures that the generated cache fields in Java are marked with @nullable if they are non-primitive types, prompting J2KT to generate nullable Kotlin properties which do not require immediate initialization.

We avoid adding @nullable to primitive types (like the boolean flag used in CheckBooleanField) because primitives cannot be annotated with @nullable in Java, and doing so would cause compilation errors.

RELNOTES=n/a

J2KT requires non-nullable Kotlin properties to be initialized. For @memoized methods returning reference types, AutoValue generates fields without initialization, relying on Java's default null initialization. If these fields are not marked @nullable in Java, J2KT generates non-nullable Kotlin properties, leading to compilation errors like "property must be initialized or be abstract".

This change ensures that the generated cache fields in Java are marked with @nullable if they are non-primitive types, prompting J2KT to generate nullable Kotlin properties which do not require immediate initialization.

We avoid adding @nullable to primitive types (like the boolean flag used in CheckBooleanField) because primitives cannot be annotated with @nullable in Java, and doing so would cause compilation errors.

RELNOTES=n/a
PiperOrigin-RevId: 906324290
@copybara-service copybara-service Bot merged commit 2f36604 into main Apr 27, 2026
@copybara-service copybara-service Bot deleted the test_903880894 branch April 27, 2026 13:37
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.

1 participant