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
Capability can't find correct enrich method #2237
Comments
Hrmmm, ok, how are you finding this issue with feign classes? |
When I was learning the source code of feign, I accidentally found it, I think it seems to be a bug, so I went to verify my idea |
Sure, a pull request is welcome. |
ok, my pleasure |
While Capability mainly enriches the Feign base components, I would like to mention that it still allows enhancements to custom components, which can be a problem if the developer is not careful。 public static class TestFeign {
|
test-code:
public class CapabilityInvokeTest {
static class TestCapability implements Capability {
public Father enrich(Father father) {
father.balance = 10;
return father;
}
public Son enrich(Son son) {
son.balance = 5;
return son;
}
}
}
**reason:**Capability.invoke method
Arrays.stream(capability.getClass().getMethods())
.filter(method -> method.getName().equals("enrich"))
.filter(method -> method.getReturnType().isAssignableFrom(capabilityToEnrich))
.findFirst()
problem:
.filter(method -> method.getReturnType().isAssignableFrom(capabilityToEnrich)).findFirst()
Father.class.isAssignableFrom(Son.class)
Son.class.isAssignableFrom(Son.class)
both return true,so findFirst allways return the first method For Father.enrich
There seem to be two ways to solve this problem
first: adjust the order in which methods are defined,defind the Son.enrich before the Father.enrich
second:
.filter(method -> method.getReturnType() == capabilityToEnrich)
The text was updated successfully, but these errors were encountered: