Skip to content

WW-2934 Skip field validators when a field has a conversion error (opt-in)#1810

Open
lukaszlenart wants to merge 5 commits into
mainfrom
WW-2934-skip-validators-on-conversion-error
Open

WW-2934 Skip field validators when a field has a conversion error (opt-in)#1810
lukaszlenart wants to merge 5 commits into
mainfrom
WW-2934-skip-validators-on-conversion-error

Conversation

@lukaszlenart

Copy link
Copy Markdown
Member

Fixes WW-2934

Problem

When a field fails type conversion (e.g. a user types one into an Integer age field), the user sees two errors for the same field:

  1. The conversion error, added by ConversionErrorInterceptor (which runs before validation in the default stack).
  2. A redundant field-validator error (e.g. required), because binding failed and the field holds its default value.

Once a value could not be converted, the field's remaining validators are operating on a value the user never entered, so they should be skipped.

Change

Adds an opt-in global constant struts.validators.skipValidatorsOnConversionError (default false — zero behavior change for existing apps).

When enabled, DefaultActionValidatorManager skips a field's remaining validators once that field has an entry in ActionContext.getConversionErrors(), with two guarantees:

  • The field's own conversion validator (ConversionErrorFieldValidator) still runs, so its (optionally custom) message is preserved.
  • Action-level (non-field) validators are untouched.

The guard sits in the single validate(...) choke point that both XML- and annotation-driven validation funnel through, and reuses the already-computed full field name (so nested/indexed fields match correctly).

Tests

DefaultActionValidatorManagerTest gains coverage for: flag off → both errors (unchanged behavior); flag on → redundant validator skipped, conversion message retained; unrelated field still validated; action-level validator unaffected; and the same skip firing through the default AnnotationActionValidatorManager. Full validator package suite: 172/172 green.

Note

This branch also includes the design spec and implementation plan under docs/superpowers/. Happy to drop those commits if you'd prefer a code-only PR.

🤖 Generated with Claude Code

lukaszlenart and others added 4 commits July 23, 2026 21:19
…rror

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ersion error

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…opt-in flag

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ror skip exemption

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in validation behavior in Struts core to avoid redundant field-validator errors when a field already has a type-conversion error, while preserving the conversion validator’s message and leaving action-level validators unchanged.

Changes:

  • Introduces the global constant struts.validators.skipValidatorsOnConversionError (default false) and documents it in default.properties.
  • Updates DefaultActionValidatorManager to skip non-conversion FieldValidators for fields present in ActionContext.getConversionErrors() when the flag is enabled.
  • Adds core tests plus fixtures to cover default behavior, enabled behavior, and the AnnotationActionValidatorManager path; includes design/plan docs under docs/superpowers/.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/superpowers/specs/2026-07-23-WW-2934-skip-validators-on-conversion-error-design.md Design spec for the opt-in skip-on-conversion-error behavior.
docs/superpowers/plans/2026-07-23-WW-2934-skip-validators-on-conversion-error.md Implementation plan documenting steps and test strategy.
core/src/main/java/org/apache/struts2/StrutsConstants.java Adds the new STRUTS_VALIDATORS_SKIP_VALIDATORS_ON_CONVERSION_ERROR constant.
core/src/main/resources/org/apache/struts2/default.properties Documents the new constant and its default value (false).
core/src/main/java/org/apache/struts2/validator/DefaultActionValidatorManager.java Injects the flag and implements the validator-skip guard based on conversion errors.
core/src/test/java/org/apache/struts2/validator/ConversionErrorSkipAction.java Test fixture action used to validate conversion-error skipping behavior.
core/src/test/resources/org/apache/struts2/validator/ConversionErrorSkipAction-validation.xml Test fixture validation rules (conversion + required + unrelated field + action-level validator).
core/src/test/java/org/apache/struts2/validator/DefaultActionValidatorManagerTest.java Adds coverage for flag off/on behavior and annotation manager path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…er nested field skip

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants