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
StringIndexOutOfBoundsException in AbstractErrors for class-level JSR-303 validator [SPR-11374] #16001
Comments
Juergen Hoeller commented I'm not entirely sure why this is being called with an empty field name at the top level (i.e. with no nested path set either). In any case, I have restored the original empty field name behavior for 4.0.2 and 3.2.8 now. Juergen |
Michael Simons commented Thanks, Jürgen. You're right, i'm wondering too. The custom validator is only in place at class level. FYI: Validation is called in a
happens with Spring 3.2.7/ Validator 4.3.1.Final and Spring 4.0.1 / Validator 5.0.3.Final |
Juergen Hoeller commented It's interesting that the empty field name case only happens with default constraint validation being active there... We'll simply have to define an empty property path as valid in a JSR-303 ConstraintValidation that we're introspecting. This simply wasn't properly defined before. The algorithm never found a FieldError for such a getFieldError("") call anyway, always considering the violation as to-be-registered. I suppose it should actually check for a top-level ObjectError in such a case, in order to not register an additional error for a pre-registered one, just like for regular fields. I'll have a look at that case. For the time being, the basic behavior is restored for the latest 4.0.2 and 3.2.8 snapshots, as a remedy for the immediate issue. Juergen |
Juergen Hoeller commented Since the check for an existing FieldError was primarily meant for binding failures, SpringValidatorAdapter's algorithm seems to be alright as-is: Global ObjectErrors can't result from binding failures to begin with. So simply accepting empty field names for getFieldError checks (again) seems to be all that's needed here. I've revised the fix in the meantime, making field error access with wildcards more efficient than before. String's substring is an expensive operation after some recent changes in the JDK 7 and 8 lines where it always creates a copy of the underlying content, so it's better to use regionMatches instead of startsWith + substring. If there is anything else that you run into here - with any combination of constraints processed by any version of Hibernate Validator -, please let me know. Juergen |
Michael Simons commented Thank you very much, this kind of support is highly appreciated and great work. I'll keep this in mind if we run into trouble again. |
Michael Simons opened SPR-11374 and commented
The performance improvement of #15928 is nice, but has one flaw. If a field name is "" (which is the case of a class level validator like the following (http://stackoverflow.com/a/2155576)
added to a class like so
it breaks with:
I have the impression it happens only in combination with other validations and with the default violations in place.
I'm adding now
to my validator which is better on it's one, but i think the slightly different semantics should be fixed.
Take care and thank you.
Affects: 3.2.7, 4.0.1
Issue Links:
Backported to: 3.2.8
The text was updated successfully, but these errors were encountered: