Skip to content

fix: keep components with JS initializers serializable (#25439) (CP: 25.2) - #25440

Merged
vaadin-bot merged 1 commit into
25.2from
cherry-pick-25439-to-25.2-1788350645103
Sep 2, 2026
Merged

vaadin-bot merged 1 commit into
25.2from
cherry-pick-25439-to-25.2-1788350645103

Conversation

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This PR cherry-picks changes from the original PR #25439 to branch 25.2.

Original PR description

Description

addAttachListener returns a registration that captures the listener, and ElementJsInitializerRegistration keeps that registration in a field of the same object. When the listener is a lambda or method reference, the two form a cycle that Java's lambda deserialization cannot resolve: the captured listener comes back as an unresolved SerializedLambda and the cast to Command fails. Session serialization of any element carrying a JS initializer therefore failed with a ClassCastException.

  • Replaced the method-reference attach listener in ElementJsInitializerRegistration with an explicit Command implementation, so it no longer serializes as a SerializedLambda
  • Added ElementTest#addJsInitializer_serializeAndDeserializeOwner_succeeds, which serializes and deserializes the state node of an element that carries an initializer

Type of change

  • Bugfix

## Description

`addAttachListener` returns a registration that captures the listener,
and `ElementJsInitializerRegistration` keeps that registration in a
field of the same object. When the listener is a lambda or method
reference, the two form a cycle that Java's lambda deserialization
cannot resolve: the captured listener comes back as an unresolved
`SerializedLambda` and the cast to `Command` fails. Session
serialization of any element carrying a JS initializer therefore failed
with a `ClassCastException`.

- Replaced the method-reference attach listener in
`ElementJsInitializerRegistration` with an explicit `Command`
implementation, so it no longer serializes as a `SerializedLambda`
- Added
`ElementTest#addJsInitializer_serializeAndDeserializeOwner_succeeds`,
which serializes and deserializes the state node of an element that
carries an initializer

## Type of change

- Bugfix

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Leif Åstrand <leif@vaadin.com>
@github-actions github-actions Bot added the +0.0.1 label Sep 2, 2026
@vaadin-bot

Copy link
Copy Markdown
Collaborator Author

This PR is eligible for auto-merging policy, so it has been approved automatically. If there are pending conditions, auto merge (with 'squash' method) has been enabled for this PR [Message is sent from bot]

@vaadin-bot
vaadin-bot enabled auto-merge (squash) September 2, 2026 12:15
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Test Results

 1 383 files  ±0   1 383 suites  ±0   1h 30m 51s ⏱️ - 1m 4s
10 342 tests +1  10 274 ✅ +1  68 💤 ±0  0 ❌ ±0 
10 697 runs  +1  10 628 ✅ +1  69 💤 ±0  0 ❌ ±0 

Results for commit 9826150. ± Comparison against base commit 4c68acb.

@vaadin-bot
vaadin-bot merged commit 6b468b9 into 25.2 Sep 2, 2026
35 checks passed
@vaadin-bot
vaadin-bot deleted the cherry-pick-25439-to-25.2-1788350645103 branch September 2, 2026 12:20
@vaadin-bot

Copy link
Copy Markdown
Collaborator Author

This ticket/PR has been released with Vaadin 25.2.8.

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.

3 participants