Skip to content

OptionWriter.renderFromMap fails when map key is null [SPR-7024] #11686

@spring-projects-issues

Description

@spring-projects-issues

Shai Yallin opened SPR-7024 and commented

When using a Map as the items values for an OptionWriter-based tag and ommiting the itemValue property (valueProperty is null), OptionWriter still creates BeanWrappers around the map key and values although they are never used.

As a result of that, one is unable to use null as a map key, which may be useful for instance when the map contains enum values as keys and their localized names as values. In this scenario, it may be useful to include null as a map key which represents an empty field value.

affected code:
{{
Object mapKey = entry.getKey();
Object mapValue = entry.getValue();
BeanWrapper mapKeyWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapKey);
BeanWrapper mapValueWrapper = PropertyAccessorFactory.forBeanPropertyAccess(mapValue);
Object renderValue = (this.valueProperty != null ? mapKeyWrapper.getPropertyValue(this.valueProperty) :
mapKey.toString());
Object renderLabel = (this.labelProperty != null ? mapValueWrapper.getPropertyValue(this.labelProperty) :
mapValue.toString());
renderOption(tagWriter, mapKey, renderValue, renderLabel);
}}

fix suggestion: only create the wrappers if this.valueProperty != null


Affects: 3.0.1

Referenced from: commits a614430

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions