You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@struts.apache.org by "lukaszlenart (via GitHub)" <gi...@apache.org> on 2026/10/05 14:18:09 UTC

[PR] WW-5757 fix(bean-validation): resolve the constraint message template as the text key [struts]

lukaszlenart opened a new pull request, #1989:
URL: https://github.com/apache/struts/pull/1989

   Fixes [WW-5757](https://issues.apache.org/jira/browse/WW-5757)
   
   `BeanValidationInterceptor` used `ConstraintViolation#getMessage()`, the message after the Bean Validation provider has interpolated it, as the Struts text key. The key a developer declares is the constraint's `message` attribute, which is `getMessageTemplate()`.
   
   ## Changes
   
   The error text is now resolved in a new protected `resolveMessage` hook:
   
   - `getMessageTemplate()` is looked up in the Struts bundles, and `getText` is called with it only when `hasKey` finds it.
   - Otherwise the provider's `getMessage()` is used as-is, as literal text. It is not passed to any text-provider method.
   - A template that only references a provider message key, like `{jakarta.validation.constraints.NotNull.message}`, is not looked up at all. Such a template can never be a Struts key. Looking it up would also send its `{jakarta` prefix through the child-property lookup, which logs a warning per violation in dev mode.
   
   ## Behaviour changes
   
   - A message produced by the provider is no longer processed as a Struts message. It is shown exactly as the provider produced it.
   - `struts.beanValidation.convertMessageToUtf` now applies only to text resolved from a Struts bundle. It exists to correct bundles read as ISO-8859-1. The provider already returns a decoded string, so re-encoding that string could only corrupt it.
   
   ## Tests
   
   - `testProviderMessageIsReportedLiterally`: a `@LuhnCheck` field with the provider's default message, which includes the validated value, is reported verbatim. It fails on the previous code.
   - `testFieldAction` now asserts the text resolved from a new `FieldAction.properties` bundle. Before this, no test covered bundle resolution: the existing key assertions passed only because `getText` falls back to the key.
   - `BeanValidationInterceptorMessageTest`: a provider-key template makes no text-provider call.
   
   The plugin documentation page will be updated in a separate struts-site PR.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WW-5757 fix(bean-validation): resolve the constraint message template as the text key [struts]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1989:
URL: https://github.com/apache/struts/pull/1989#discussion_r4191842462


##########
plugins/bean-validation/src/main/java/org/apache/struts/beanvalidation/validation/interceptor/BeanValidationInterceptor.java:
##########
@@ -135,16 +137,7 @@ protected void addBeanValidationErrors(Set<ConstraintViolation<Object>> constrai
         if (constraintViolations != null) {
             ValidatorContext validatorContext = new DelegatingValidatorContext(action, textProviderFactory);
             for (ConstraintViolation<Object> constraintViolation : constraintViolations) {
-                String key = constraintViolation.getMessage();
-                String message = key;
-                try {
-                    message = validatorContext.getText(key);
-                    if (convertToUtf8 && StringUtils.isNotBlank(message)) {
-                        message = new String(message.getBytes(convertFromEncoding), "UTF-8");
-                    }
-                } catch (Exception e) {
-                    LOG.error("Error while trying to fetch message: {}", key, e);
-                }
+                String message = resolveMessage(constraintViolation, validatorContext);

Review Comment:
   This change touches security-sensitive framework code. Please confirm it is not a fix for a suspected vulnerability before merging — see `SECURITY.md`. Vulnerability fixes go through the private process at `security@struts.apache.org`, not a public pull request.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WW-5757 fix(bean-validation): resolve the constraint message template as the text key [struts]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #1989:
URL: https://github.com/apache/struts/pull/1989#issuecomment-5999040949

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=1989) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=1989&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_struts&pullRequest=1989&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_struts&pullRequest=1989&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1989&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1989&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=1989)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WW-5757 fix(bean-validation): resolve the constraint message template as the text key [struts]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #1989:
URL: https://github.com/apache/struts/pull/1989#issuecomment-5996681184

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=1989) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [71.4% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_struts&pullRequest=1989&metric=new_coverage&view=list) (required ≥ 80%)  
     
   <!-- sqra:qg_revision=0e9ea768578ee329af0a91f1d8079b46040b7cb508c05f6162c99b3f5eca43d5 -->
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_struts&pullRequest=1989)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] WW-5757 fix(bean-validation): resolve the constraint message template as the text key [struts]

Posted by "lukaszlenart (via GitHub)" <gi...@apache.org>.
lukaszlenart merged PR #1989:
URL: https://github.com/apache/struts/pull/1989


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@struts.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org