Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
th:hasErrors() creates model attributes if not present (side-effect) [SPR-17567] #22099
I'm not 100% sure this is a problem of spring core or perhaps thymeleaf (due to my lack of knowledge of internals), but I suspect the problem is actually with spring:
Calling th:hasErrors() in a thymeleaf template can have the potentially unwanted side-effect of creating model attributes while evaluating the thymeleaf template.
One way I found to reproduce this is using uninitialized nested model attributes. If I have a model attribute that has another object as a field, and that field is not initialized per construction, it will be initialized upon calling th:hasErrors() on it.
For example, I have a model attribute
I don't think hasErrors() should have such unexpected side effects.
I made a minimal modification to the spring example project gs-validating-form-input to demonstrate/reproduce the issue: McNetic/gs-validating-form-input@55a265f
(I know the examples are not very meaningful)
Reference URL: McNetic/gs-validating-form-input@55a265f