Skip to content

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

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

Closed
spring-projects-issues opened this issue Apr 21, 2016 · 2 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

Referenced from: commits ce2f28d

@spring-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

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
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants