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

Spring cannot find setter if subclass overrides getter narrowing return type [SPR-10995] #15623

Closed
spring-issuemaster opened this issue Oct 16, 2013 · 6 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Oct 16, 2013

Piotr Findeisen opened SPR-10995 and commented

Steps to Reproduce

  1. Create a class with a property (getter/setter) of type Bar.
  2. Create a subclass that overrides the getter narrowing the return type to MoreBar extends Bar.
  3. Try to set the property in XML config.

Expectation

It worked in 3.1.2, so it should work now.

Failing Exception

org.springframework.beans.factory.BeanCreationException: Error creating bean ...
...
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'bar' of bean class [...]: Bean property 'bar' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Affects: 3.1.4

0 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 16, 2013

Piotr Findeisen commented

I've implemented a test that passes with spring 3.1.2 but fails with 3.1.4

I was running the test using Open JDK 1.6.0_27 and 1.7.0_21 (with no difference).

I've trouble setting the priority.

For me this is a BLOCKER preventing me from upgrading from 3.1.2 to 3.1.4.
(I know I should fix the code, but that is not so simple in big project -- especially if I don't have 100% test coverage yet.)

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 18, 2013

Phil Webb commented

Repro project is now in spring-framework-issues

spring-projects/spring-framework-issues@de6a0bf

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 26, 2013

Juergen Hoeller commented

As far as I can verify, this has been fixed in the 4.0 line already. However, the test fails against the current state in the 3.2.x branch. I'll make sure to backport whatever's necessary from 4.0 to 3.2.5 there.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 26, 2013

Juergen Hoeller commented

Actually, it's not fixed in 4.0 itself, it's fixed in JDK 8 which we run the 4.0 tests against by default. So we'll have to find a fix for 4.0 as well when running on JDK 6/7.

We're using the JDK's JavaBeans Introspector, so we 'inherit' any new behavior implemented there.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 26, 2013

Juergen Hoeller commented

Fixed through a more lenient fallback check for a setter method in case of the getter having been found with covariant return type narrowing.

We had a fallback before but it turned out to be not lenient enough, at least not on JDKs before 8.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 27, 2013

Piotr Findeisen commented

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.