Invoke init/destroy/SpEL methods via public declaring type whenever possible #33216
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Overview
The original scope of this issue was limited to method invocations in SpEL expressions (see below); however, after further investigation we have decided to apply the same enhancement for
init
anddestroy
methods inspring-beans
.For reflective method invocation in the Spring Expression Language (SpEL), we currently use
ClassUtils.getInterfaceMethodIfPossible(...)
to attempt to invoke the method via an interface, based on the rationale stated in the Javadoc for that utility.This works well for methods which are actually defined in an interface, but it does not work for methods defined in a superclass.
For example, in a SpEL expression it is currently impossible to invoke
toString()
on a non-public type in a different module. This can be seen when attempting to invoketoString()
on an unmodifiable list created byCollections.unmodifiableList(...)
. Doing so results in an exception similar to the following.Users can address this by adding an appropriate
--add-opens
declaration, such as--add-opens java.base/java.util=ALL-UNNAMED
.However, it would be nice if applications did not have to add such an
--add-opens
declaration for such use cases in SpEL.For compiled expressions, we added support in #29857 to invoke the method via a public declaring type, since that is an actual requirement for compiled Java code. So, we should consider doing the same for methods invoked via reflection.
Related Issues
The text was updated successfully, but these errors were encountered: