Skip to content

fix: show validation error when null is bound to primitive bean property#24266

Merged
mcollovati merged 3 commits intovaadin:mainfrom
adraarda23:fix/binder-primitive-null-validation
May 6, 2026
Merged

fix: show validation error when null is bound to primitive bean property#24266
mcollovati merged 3 commits intovaadin:mainfrom
adraarda23:fix/binder-primitive-null-validation

Conversation

@adraarda23
Copy link
Copy Markdown
Contributor

When a field bound to a primitive property (e.g. double) produces a null value through converters, the Binder now returns a descriptive validation error instead of throwing a NullPointerException.

Fixes #24253

Description

When a Binder field is bound to a primitive bean property (e.g. double) via bind("propertyName"), and the field value becomes null through
a converter chain (for example StringToBigDecimalConverterBigDecimalToDoubleConverter producing null), the Binder was throwing a
NullPointerException instead of showing a user-facing validation error.

This fix detects primitive-typed properties in bind(String propertyName) and adds a converter that returns a descriptive Result.error(...)
when the value is null, preventing the NPE and surfacing a meaningful message.

Fixes #24253

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

When a field bound to a primitive property (e.g. double) produces a null
value through converters, the Binder now returns a descriptive validation
error instead of throwing a NullPointerException.

Fixes vaadin#24253
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented May 5, 2026

CLA assistant check
All committers have signed the CLA.

@mcollovati mcollovati added the Contribution PRs coming from the community or external to the team label May 5, 2026
@github-actions github-actions Bot added the +0.0.1 label May 6, 2026
Comment thread flow-data/src/test/java/com/vaadin/flow/data/binder/BinderTest.java Outdated
Comment thread flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Test Results

 1 404 files  ±0   1 404 suites  ±0   1h 15m 20s ⏱️ - 1m 2s
10 127 tests +1  10 057 ✅ +1  70 💤 ±0  0 ❌ ±0 
10 602 runs  +1  10 523 ✅ +1  79 💤 ±0  0 ❌ ±0 

Results for commit 9941df8. ± Comparison against base commit b262002.

♻️ This comment has been updated with latest results.

- Clarify that asRequired must be placed before any converter
- Simplify test to use StringToDoubleConverter directly
mcollovati
mcollovati previously approved these changes May 6, 2026
Copy link
Copy Markdown
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the contribution!

@github-actions github-actions Bot added +1.0.0 and removed +0.0.1 labels May 6, 2026
@mcollovati mcollovati enabled auto-merge May 6, 2026 08:48
@github-actions github-actions Bot added +0.0.1 and removed +1.0.0 labels May 6, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

@mcollovati mcollovati added this pull request to the merge queue May 6, 2026
Merged via the queue into vaadin:main with commit ba49acd May 6, 2026
31 checks passed
@adraarda23 adraarda23 deleted the fix/binder-primitive-null-validation branch May 6, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contribution PRs coming from the community or external to the team +0.0.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NULL value always in the valid range inside RangeValidator.isValid

2 participants