Skip to content

GH-3079: Use getMostSpecificMethod for SpEL calls #3082

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

Merged
merged 2 commits into from
Oct 16, 2019

Conversation

artembilan
Copy link
Member

Fixes #3079

It turns out that we need to use a most specific method for the target
to be called reflectively from the SpEL

NOTE: We drop a Method not found error in case of wrong method source
since now we find a right source via ClassUtils.getMostSpecificMethod()

Cherry-pick to 5.1.x

Copy link
Contributor

@garyrussell garyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; but see comment regarding removed test.

@@ -700,7 +701,15 @@ public IntegrationFlow wireTapFlow4() {
public IntegrationFlow wireTapFlow5() {
return f -> f
.wireTap(sf -> sf
.<String, String>transform(String::toUpperCase)
.transform(// Must not be lambda for SpEL fallback behavior on empty payload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why the payload resolver doesn't allow an empty string but I suppose it's rare so falling back to SpEL is ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I treat this like a note and not as some confusion or advice to change something.
Correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's fine; I was just making a comment; since the problem only arises with an empty payload.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it also is there when we use a @UseSpelInvoker.

I believe I had to come up with the @Transformer against that GenericTransformer impl test-case, but it doesn't matter so far: I don't think it makes sense to use @Transformer and don't rely on powerful POJO method call support.

.isThrownBy(() -> processor.processMessage(new GenericMessage<>("foo")))
.withCauseInstanceOf(SpelEvaluationException.class);
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm - I don't think this is right - there is no relationship between the methods on these two classes - it looks like getMostSpecificMethod() doesn't check that the method is in the class hierarchy - seems like a bug to me. I think this test should still pass.

Consider ignoring instead and perhaps open an issue in SF to see whether they consider the behavior to be correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Makes sense.
It bumped me as well: why getMostSpecificMethod() doesn't care about the class of source.

I'll revert the test change with an appropriate @Ignore.

We still don't pass for Kotlin variant, but that's also out of SI scope...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's intentional...

return targetClass.getMethod(method.getName(), method.getParameterTypes());

But it seems odd to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes spring-projects#3079

It turns out that we need to use a *most specific* method for the target
to be called reflectively from the SpEL

NOTE: We drop a *Method not found* error in case of wrong method source
since now we find a right source via `ClassUtils.getMostSpecificMethod()`

**Cherry-pick to 5.1.x**
@garyrussell garyrussell merged commit 3366788 into spring-projects:master Oct 16, 2019
garyrussell pushed a commit that referenced this pull request Oct 16, 2019
* GH-3079: Use getMostSpecificMethod for SpEL calls

Fixes #3079

It turns out that we need to use a *most specific* method for the target
to be called reflectively from the SpEL

NOTE: We drop a *Method not found* error in case of wrong method source
since now we find a right source via `ClassUtils.getMostSpecificMethod()`

**Cherry-pick to 5.1.x**

* * `@Ignore` `MethodInvokingMessageProcessorTests.testProcessMessageMethodNotFound()`
instead of removal
@garyrussell
Copy link
Contributor

Cherry-picked as 80ed25e after resolving conflicts.

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

Successfully merging this pull request may close these issues.

SpEL invocation for functional interfaces cannot find the method for signature
2 participants