Skip to content

BeanUtils.copyProperties() to not set collection fields of wrong generic type [SPR-15689] #20248

@spring-projects-issues

Description

@spring-projects-issues

Elad Tabak opened SPR-15689 and commented

org.springframework.beans.BeanUtils.copyProperties() copy fields of generic collections even if the generic types do not match.
This result in a strange behavior when a bean that have a collection of <A> will get values of <B>.
See example class:
There are two bean classes - X and Y. Both have a field "list" of different types - X have a list of <A> and Y have a list of <B>.
The result after a BeanUtils.copyProperties(x,y) is that y have a list of <A> even though it's a type mismatch.

Generic data is problematic to establish in case the collection is empty, but if it's not, it's possible to not set the field. Of course this is a best-effort for a specific use case of 2 beans of different types.


Affects: 4.3.9

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions