Skip to content

WW-5818 Optionally fail a validator whose param cannot be converted - #2198

Open
emilhuseyn wants to merge 1 commit into
apache:mainfrom
emilhuseyn:WW-5818-fail-on-bad-validator-param
Open

emilhuseyn wants to merge 1 commit into
apache:mainfrom
emilhuseyn:WW-5818-fail-on-bad-validator-param

Conversation

@emilhuseyn

Copy link
Copy Markdown
Contributor

Fixes WW-5818

Since WW-5819, factory.DefaultValidatorFactory logs a validator param that cannot be converted (WARN, ERROR in devMode) and builds the validator with the param unset. For a range bound that still turns the check off, for example <param name="min">01/02/2026</param> on localdate.

The ticket targets 8.0.0 because failing here breaks applications whose misconfigured param has gone unnoticed. main is still 7.6.0, so this follows the pattern of struts.parameters.requireAnnotations.enforceOnResolvedMember: the new behaviour sits behind a constant that defaults to false, and 8.0.0 can flip the default with a migration note.

  • New constant struts.validators.failOnUnconvertibleParam (StrutsConstants.STRUTS_VALIDATORS_FAIL_ON_UNCONVERTIBLE_PARAM), documented in default.properties, default false.
  • With it on, setParam throws a ConfigurationException naming the validator class, the param, the value and the root cause, instead of logging. validator.DefaultValidatorFactory.getValidator already wraps that in a StrutsException carrying the ValidatorConfig, so the error points at the XML location.
  • The same rule as the WW-5819 logging decides which params count: only a param with a writable property. The methodName routing param the annotation builder adds, and misspelled param names, stay silent as before. The WW-5819 Log a validator param that fails type conversion #2062 description says misspelled names belong with WW-5818; I left them out because telling them apart from routing params needs a list of those params, and I would rather ask first. Happy to add it here or in a follow-up.
  • With it off nothing changes: the existing WARN and devMode ERROR tests pass unchanged.

Validators are built from the cached configs each time an action is validated, so with the constant on a bad param fails that action's validation on every request rather than failing at startup. That is still a visible error where today the check is skipped without one.

Tests in DefaultValidatorFactoryTest, with the constant on:

  • min = 01/02/2026 on localdate and min = abc on int fail with a StrutsException whose cause is a ConfigurationException naming the param and the value
  • a convertible min and a required validator with the methodName param still build, with nothing logged

The two failing-case tests fail on main (the validator is built) and pass with the change. DefaultValidatorFactoryTest and the other *Validator* and *Validation* tests pass locally on JDK 21, along with the full core suite.

Not in this PR: flipping the default and the migration guide entry, which belong with the 8.0.0 branch.

🤖 Generated with Claude Code

…not be converted

Adds struts.validators.failOnUnconvertibleParam (default false). When
set, DefaultValidatorFactory throws a ConfigurationException naming the
validator, the param, the value and the cause, instead of logging the
conversion error and building the validator with the param unset, which
turns a range check off. Only params with a writable property count, as
for the WW-5819 logging. 8.0.0 can flip the default.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:32

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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