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

Java 8 default methods not detected as bean properties [SPR-14198] #18772

Closed
spring-issuemaster opened this issue Apr 21, 2016 · 2 comments
Closed
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Apr 21, 2016

Conor Gallagher opened SPR-14198 and commented

As the title suggests, Spring 4.2.5.RELEASE cannot inject into Java 8 default methods via xml context files.

I have thrown together a simple example on GitHub to demonstrate how this fails:

    void setSomeDate(LocalDate localDate);

    default void setSomeDateInDayMonthYear(String dayMonthYear) {
        setSomeDate(LocalDate.parse(dayMonthYear, DateTimeFormatter.ofPattern("dd/MM/yyyy")));
    }

An egregious workaround is to reference the default method from the implementation as follows:

@Override
public void setSomeDateInDayMonthYear(String dayMonthYear) {
    SomeInterface.super.setSomeDateInDayMonthYear(dayMonthYear);
}

Also referenced on SO:
http://stackoverflow.com/questions/30477367/spring-4-cannot-execute-java-8-default-methods


Affects: 4.2.5

Reference URL: https://github.com/cjbooms/spring-default-methods

Issue Links:

  • #15547 @Bean on Java 8 default methods in interfaces
  • #21516 CachedIntrospectionResults should build complete descriptor for setter/getter across interface hierarchy
  • #20869 CachedIntrospectionResults should use BeanInfoFactory when introspecting implemented interfaces

Referenced from: commits ce2f28d

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 27, 2016

Juergen Hoeller commented

Unfortunately, even the JDK's own JavaBeans Introspector does not detect setters and getters as default methods. I've added some explicit code to our CachedIntrospectionResults, querying the introspector explicitly for each implemented interface and adding missing bean properties that way.

This will be available in the upcoming 4.3.0.BUILD-SNAPSHOT and make it into 4.3 RC2.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 27, 2016

Conor Gallagher commented

Great work, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.