Skip to content
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

BeanUtils does not copy properties with generics from a Proxy since 5.3.0 #26531

Closed
rreitmann opened this issue Feb 8, 2021 · 8 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@rreitmann
Copy link

After upgrading from spring boot 2.3.8 to 2.4.2 our following test case fails:
CopyPropertiesTest

Basically it loads a spring data projection from MongoDB and tries to copy all of its properties with Spring's BeanUtils.copyProperties into another bean. For some reason "collection"-properties are not copied anymore after the upgrade.

@philwebb
Copy link
Member

philwebb commented Feb 8, 2021

I'm afraid I can't build that application:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.630 s
[INFO] Finished at: 2021-02-08T10:15:22-08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project metadatamanagement: Could not resolve dependencies for project eu.dzhw.fdz:metadatamanagement:war:1.0.107-SNAPSHOT: Failed to collect dependencies at pl.allegro.tech:embedded-elasticsearch:jar:2.11.3: Failed to read artifact descriptor for pl.allegro.tech:embedded-elasticsearch:jar:2.11.3: Could not transfer artifact pl.allegro.tech:embedded-elasticsearch:pom:2.11.3 from/to github (https://maven.pkg.github.com/dzhw/embedded-elasticsearch): Not authorized , ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

Can you isolate the problem into a smaller sample that we can easily run? I can't see any obvious change in BeanUtils.copyProperties so I suspect the problem might be elsewhere.

@mbhave
Copy link
Contributor

mbhave commented Feb 8, 2021

BeanUtils is a Spring Framework class so there isn't anything that we can do about this in Spring Boot itself. This could be related to this change but we would need the Spring Framework team to confirm this.

@rreitmann
Copy link
Author

I could set up a smaller spring boot project in order to demonstrate this. However, I am afraid I won't be able to do this before friday. Would that be ok for you?

@philwebb
Copy link
Member

philwebb commented Feb 8, 2021

@rreitmann That would be great, thanks. The waiting-for-feedback bot might start nagging you, but we'll just reset it if that happens.

@rreitmann
Copy link
Author

I had some time for this today, so here is the test in a smaller project which fails in 2.4.2 but passes in 2.3.8:
CopyPropertiesExampleApplicationTests

@philwebb philwebb transferred this issue from spring-projects/spring-boot Feb 9, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 9, 2021
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 11, 2021
@sbrannen
Copy link
Member

I have confirmed that this is a regression beginning with Spring Framework 5.3.0 due to #24281 as suggested by @mbhave.

My initial analysis is that the type information is lost when using ResolvableType.forMethodReturnType(...) for the getOrderLineItems() method in the proxy for the OrderProjection (note that Spring Data creates a proxy that implements the OrderProjection interface). Thus, we are effectively now comparing List<?> to List<String>, deciding that is a mismatch, and skipping the orderLineItems property.

@sbrannen sbrannen self-assigned this Feb 11, 2021
@sbrannen sbrannen changed the title BeanUtils does not copy all properties of a projection after upgrading from 2.3.8 to 2.4.2 BeanUtils does not copy properties with generics from a Proxy since 5.3.0 Feb 11, 2021
@sbrannen sbrannen added this to the 5.3.4 milestone Feb 11, 2021
@sbrannen
Copy link
Member

This has been fixed in master and will be available in the upcoming 5.3.4 snapshot.

Feel free to give it a try and let us know if you run into any issues.

@rreitmann
Copy link
Author

Thanks for the quick fix, I will wait until it is part of a spring boot release.

This was referenced Mar 13, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
spring-projectsgh-24281 introduced support to honor generic type information in
BeanUtils.copyProperties(), but that introduced a regression.
Specifically, if the supplied source or target object lacked generic
type information for the return type of the read-method or the
parameter type of the write-method for a given property, respectively,
the two properties would be considered a mismatch and ignored. This can
occur if the source or target object is a java.lang.reflect.Proxy since
the dynamically generated class for the proxy loses the generic type
information from interfaces that the proxy implements.

This commit fixes this regression by ignoring generic type information
if either the source or target property is lacking generic type
information.

Closes spring-projectsgh-26531
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants