New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rejected value is null when configuration property fails validation #19580
Comments
@tazle A sample that we can use to reproduce the issue would be very helpful, thanks. |
This comment has been minimized.
This comment has been minimized.
@tazle thank you for the sample but rather than code in text, please create a project (either a github project or a zip) as we'd have to copy paste all that in order to do something useful with it anyway. |
Zipped up: |
Looks like gh-17424 is a cause. org.springframework.boot.context.properties.source.InvalidConfigurationPropertyNameException: Configuration property name 'camelCaseValue' is not valid
at org.springframework.boot.context.properties.source.ConfigurationPropertyName.elementsOf(ConfigurationPropertyName.java:522)
at org.springframework.boot.context.properties.source.ConfigurationPropertyName.probablySingleElementOf(ConfigurationPropertyName.java:495)
at org.springframework.boot.context.properties.source.ConfigurationPropertyName.append(ConfigurationPropertyName.java:191)
at org.springframework.boot.context.properties.bind.validation.ValidationBindHandler$ValidationResult.getName(ValidationBindHandler.java:190)
at org.springframework.boot.context.properties.bind.validation.ValidationBindHandler$ValidationResult.getFieldType(ValidationBindHandler.java:168)
at org.springframework.validation.AbstractBindingResult.resolveMessageCodes(AbstractBindingResult.java:325)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.processConstraintViolations(SpringValidatorAdapter.java:175)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:109)
at org.springframework.boot.context.properties.ConfigurationPropertiesJsr303Validator.validate(ConfigurationPropertiesJsr303Validator.java:51)
at org.springframework.boot.context.properties.bind.validation.ValidationBindHandler.validateAndPush(ValidationBindHandler.java:132)
at org.springframework.boot.context.properties.bind.validation.ValidationBindHandler.validate(ValidationBindHandler.java:110)
at org.springframework.boot.context.properties.bind.validation.ValidationBindHandler.onFinish(ValidationBindHandler.java:102)
at org.springframework.boot.context.properties.bind.Binder.handleBindResult(Binder.java:340)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:321) problem line: Line 190 in c584334
Btw, I have found that Line 180 in c584334
DEBUG level.
This issue can be easily fixed with: return this.name.append(DataObjectPropertyName.toDashedForm(field)); But I am not sure about this and in addition |
Thanks for the analysis, @nosan. I was initially planning to change the code to skip validation if a previous validation exception was found and that would've fixed this issue as a side effect. I decided to create a separate issue for that. |
This fix seems to have gotten rid of some of the issues, but others still persist. I'll create a test case. |
Perhaps that was a transient issue with IDEA and outdated classpath before Maven reimport. |
After changing from Spring Boot 2.1.9 to Spring Boot 2.2.2, the error messages about constraint validation for some of our configuration properties started including null as the rejected value, rather than the actual value (-1 in this case).
The root cause seems to be that SpringValidationAdapter's
getRejectedValue(ield, violation, bindingResult)
has started returning null in certain cases with thebindingResult
that's present in 2.2.2. Or rather, thegetRawFieldValue(String)
has started returning null.Failing case in 2.2.2:
SpringValidationAdapter
callsValidationBindHandlers$ValidationResult.getRawFieldValue("intermediatefield.leafFieldInCamelCase")
which returns null because it expects field names in form "intermediatefield.leaf-field-in-camel-case".Working case in 2.1.9:
SpringValidationAdapter
callsBeanPropertyBindingResult.getRawFieldValue("intermediatefield.leafFieldInCamelCase")
which returns the actual field value.I'll try to produce a minimal reproduction later.
The text was updated successfully, but these errors were encountered: