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

ActionPropertyAccessor compatibility issue with Spring Framework 6.2 #1819

Conversation

sbrannen
Copy link
Member

@sbrannen sbrannen commented Nov 9, 2024

Overview

Prior to this PR, if a Spring Expression Language (SpEL) expression did not include parentheses for a MultiAction method that does not accept a RequestContext argument, the flow would pass on Spring Framework versions prior to 6.2, but the same flow would fail on Spring Framework 6.2 M1 or later. The following is such an expression and is effectively a property reference which must be handled by a registered PropertyAccessor: reportActions.evaluateReport.

The reason for the change in behavior is that Spring Framework 6.2 M1 includes a bug fix for ordering SpEL PropertyAccessors. That bug fix correctly results in Spring Web Flow's ActionPropertyAccessor being evaluated before SpEL's ReflectivePropertyAccessor. Consequently, an expression such as reportActions.evaluateReport is now handled by ActionPropertyAccessor which indirectly requires that the action method accept a RequestContext argument. When the method does not accept a RequestContext argument, the flow fails with a NoSuchMethodException.

To address that, this PR revises the implementation of canRead(...) in ActionPropertyAccessor so that it only returns true if the action method accepts a RequestContext argument. When ActionPropertyAccessor's canRead(...) method returns false, the generic ReflectivePropertyAccessor will be used instead, which restores the pre-6.2 behavior for such expressions.

The test suite passes for the following Spring Framework versions.

  • ./gradlew -PspringFrameworkVersion=6.0.23 --rerun-tasks clean check
  • ./gradlew -PspringFrameworkVersion=6.1.14 --rerun-tasks clean check
  • ./gradlew -PspringFrameworkVersion=6.2.0-RC3 --rerun-tasks clean check

Related Issues

Prior to this commit, if a Spring Expression Language (SpEL) expression
did not include parentheses for a MultiAction method that does not
accept a RequestContext argument, the flow would pass on Spring
Framework versions prior to 6.2, but the same flow would fail on Spring
Framework 6.2 M1 or later. The following is such an expression and is
effectively a property reference which must be handled by a registered
PropertyAccessor: "reportActions.evaluateReport".

The reason for the change in behavior is that Spring Framework 6.2 M1
includes a bug fix for ordering SpEL PropertyAccessors. That bug fix
correctly results in Spring Web Flow's ActionPropertyAccessor being
evaluated before SpEL's ReflectivePropertyAccessor. Consequently, an
expression such as "reportActions.evaluateReport" is now handled by
ActionPropertyAccessor which indirectly requires that the action method
accept a RequestContext argument. When the method does not accept a
RequestContext argument, the flow fails with a NoSuchMethodException.

To address that, this commit revises the implementation of canRead(...)
in ActionPropertyAccessor so that it only returns `true` if the action
method accepts a RequestContext argument. When ActionPropertyAccessor's
canRead(...) method returns `false`, the generic
ReflectivePropertyAccessor will be used instead, which restores the
pre-6.2 behavior for such expressions.

The test suite passes for the following Spring Framework versions.

- ./gradlew -PspringFrameworkVersion=6.0.23 --rerun-tasks clean check
- ./gradlew -PspringFrameworkVersion=6.1.14 --rerun-tasks clean check
- ./gradlew -PspringFrameworkVersion=6.2.0-RC3 --rerun-tasks clean check

See spring-projects/spring-framework#33861
See spring-projects/spring-framework#33862
Closes spring-projectsgh-1802
@rstoyanchev rstoyanchev self-assigned this Nov 13, 2024
@rstoyanchev rstoyanchev added this to the 3.0.1 milestone Nov 13, 2024
@rstoyanchev rstoyanchev merged commit c10e233 into spring-projects:main Nov 20, 2024
1 check passed
@rstoyanchev rstoyanchev changed the title Fix ActionPropertyAccessor on Spring Framework 6.2 Ensure ActionPropertyAccessor works as before on Spring Framework 6.2 Nov 20, 2024
@rstoyanchev rstoyanchev changed the title Ensure ActionPropertyAccessor works as before on Spring Framework 6.2 ActionPropertyAccessor compatibility issue with Spring Framework 6.2 Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

An action without parameters results in NoSuchMethodException starting with Spring Framework 6.2.0-M1
2 participants