Skip to content

fix(vaadin-spring): read vaadin.* properties in native images - #26039

Merged
platosha merged 3 commits into
mainfrom
fix/spring-native-init-parameters
Sep 29, 2026
Merged

platosha merged 3 commits into
mainfrom
fix/spring-native-init-parameters

Conversation

@mcollovati

@mcollovati mcollovati commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

behavior deviation · vaadin-spring · Spring Boot apps built as a
GraalVM native image

In a Spring Boot native image, Flow ignored every vaadin.* property in
application.properties. For example vaadin.productionMode=true had no
effect, so an app without a flow-build-info.json token file started in
development mode and failed with "'vaadin-dev-server' not found". There is
no workaround other than servlet init parameters set in code.

Risks:

  • ⚠️ Behaviour change: native apps now read vaadin.* properties, as JVM
    apps always did. A wrong value in the file that nobody noticed is now used.
  • ⚠️ Behaviour change: native apps now use the Spring lookup, so services
    that Spring apps provide as beans (not only the configuration factory) are
    used as on the JVM. Before, the default implementations were used silently.
  • ✅ No breaking change, public API, security, memory, serialization,
    threading, performance or migration impact.

Context. Two reflection calls had no native hint. The property names
come from the constants in InitParameters, and the list was empty. Flow
keeps a lookup initializer only if reflection finds its public no-arg
constructor, so it dropped SpringLookupInitializer and used the default
lookup, which does not see Spring beans or Spring properties.

  • Registered the declared fields of InitParameters in
    VaadinHintsRegistrar, read by SpringServlet with getDeclaredFields()
  • Registered the public constructors of SpringLookupInitializer in
    VaadinHintsRegistrar, checked with getConstructors() and then called
    by LookupServletContainerInitializer
  • Added tests to VaadinHintsRegistrarTest that check both hints

The list of properties copied from application.properties is built
from the fields of InitParameters with reflection. Without a runtime
hint the native image returned no fields, so all vaadin.* properties
were ignored.
@mcollovati

Copy link
Copy Markdown
Collaborator Author

Type of change

  • Bugfix

How to test

  1. Clone https://github.com/mcollovati/vaadin-native-reflection and point
    it to a Flow snapshot that contains this change.
  2. Set JAVA_HOME to a GraalVM or Mandrel installation and run
    ./run-native.sh spring.
  3. Check 4a ("vaadin.* property from application.properties") passes.
    Without this change it fails with "vaadin.heartbeatInterval=123 was not
    read (got 'null')".

@mcollovati
mcollovati marked this pull request as ready for review September 29, 2026 09:38
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 551 files  ±0   1 635 suites  ±0   1h 42m 23s ⏱️ + 1m 14s
12 474 tests +2  12 402 ✅ +2  72 💤 ±0  0 ❌ ±0 
12 873 runs  +2  12 801 ✅ +2  72 💤 ±0  0 ❌ ±0 

Results for commit 22dad4e. ± Comparison against base commit a39ec5d.

♻️ This comment has been updated with latest results.

@mcollovati
mcollovati marked this pull request as draft September 29, 2026 14:39
Flow keeps only lookup initializers with a public no-arg constructor
visible to getConstructors(). In a native image the constructor was not
registered, so Flow silently used the default LookupInitializer, which
ignores Spring beans such as the configuration factory that reads
vaadin.* properties.
@mcollovati
mcollovati marked this pull request as ready for review September 29, 2026 14:48
@github-actions

Copy link
Copy Markdown
Contributor

Without the two native hints, reflection quietly returns empty, so the servlet blanks the property list and falls back to the default lookup

flowchart LR
    subgraph Before
        direction TB
        B1["VaadinHintsRegistrar.registerHints() (no hints)"]
        B2["InitParameters.class.getDeclaredFields() returns []"]
        B3["SpringServlet.PROPERTY_NAMES = [] (vaadin.* ignored)"]
        B4["ReflectTools.isInstantiableService(SpringLookupInitializer) returns false"]
        B5["LookupServletContainerInitializer falls back to LookupInitializer"]
        B1 -->|"leaves reflection metadata stripped"| B2
        B2 -->|"empty field list"| B3
        B1 -->|"leaves reflection metadata stripped"| B4
        B4 -->|"excludes class from services"| B5
    end
    subgraph After
        direction TB
        A1["VaadinHintsRegistrar registers InitParameters fields and SpringLookupInitializer ctor"]:::changed
        A2["InitParameters.class.getDeclaredFields() returns vaadin.* names"]
        A3["SpringServlet.PROPERTY_NAMES populated"]
        A4["ReflectTools.isInstantiableService(SpringLookupInitializer) returns true"]
        A5["LookupServletContainerInitializer selects SpringLookupInitializer"]:::changed
        A1 -->|"keeps reflection metadata"| A2
        A2 -->|"vaadin.* names collected"| A3
        A1 -->|"keeps reflection metadata"| A4
        A4 -->|"includes class in services"| A5
    end
    Before ~~~ After
    classDef changed stroke:#c9a227,stroke-width:3px
Loading

Per the pull request description, two reflection calls had no native-image hint: InitParameters.class.getDeclaredFields(), read by SpringServlet.PROPERTY_NAMES, and SpringLookupInitializer's constructor, checked via getConstructors() inside ReflectTools.isInstantiableService() and used by LookupServletContainerInitializer to pick a lookup implementation. Both reflection calls returned empty in the native image without a hint, so the property list stayed blank and the default LookupInitializer was silently used instead of SpringLookupInitializer. The fix adds both hints in VaadinHintsRegistrar.registerHints().

Diagram Bot draws the mechanism this pull request touches; it does not review the change. Verify it against the diff.

Generated by Diagram Bot for #26039 · agent · 51 AIC · ⌖ 5.03 AIC · ⊞ 9.1K · ◷

@sonarqubecloud

Copy link
Copy Markdown

@platosha
platosha added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit b62e1a1 Sep 29, 2026
55 checks passed
@platosha
platosha deleted the fix/spring-native-init-parameters branch September 29, 2026 15:37
@github-actions

Copy link
Copy Markdown
Contributor

Documentation Bot: No documentation needed for this change.

This PR is an INTERNAL_ONLY change: it adds two missing GraalVM native-image reflection hints (for InitParameters fields and the SpringLookupInitializer constructor) in VaadinHintsRegistrar, plus tests for them. The existing documentation (e.g. articles/flow/configuration/properties.adoc) already describes vaadin.* properties as readable via application.properties in Spring Boot apps, with no native-image exception carved out — this fix makes native images match that already-documented behavior instead of introducing anything new for a reader to learn.

Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.

Generated by Documentation Bot for #26039 · agent · 53 AIC · ⌖ 5.12 AIC · ⊞ 11.7K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants