Skip to content

Validation for nested properties is buggy [SPR-7019] #11681

@spring-projects-issues

Description

@spring-projects-issues

Oliver Becker opened SPR-7019 and commented

When validating nested properties, Spring computes a wrong property path (a.k.a. fieldname).

See org.springframework.validation.AbstractBindingResult

public String[] resolveMessageCodes(String errorCode, String field) {
	String fixedField = fixedField(field);
	Class fieldType = getFieldType(fixedField);
	return getMessageCodesResolver().resolveMessageCodes(errorCode, getObjectName(), fixedField, fieldType);
}

The problem is that getFieldType will be called already with a fixedField parameter. However, getFieldType again invokes fixedField(String) with the passed string. So in the end the fixedField method will be called twice, which in turn prepends a nestedPath twice.

The quickfix is most probably to change the second line of resolveMessageCodes into
Class fieldType = getFieldType(field);


Affects: 3.0.1

Referenced from: commits a2c3274

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions