-
Notifications
You must be signed in to change notification settings - Fork 38k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invoke init/destroy/SpEL methods via public types whenever possible
Prior to this commit, when invoking init methods and destroy methods for beans as well as methods within Spring Expression Language (SpEL) expressions via reflection, we invoked them based on the "interface method" returned from ClassUtils.getInterfaceMethodIfPossible(). That works well for finding methods defined in an interface, but it does not find public methods defined in a public superclass. For example, in a SpEL expression it was previously impossible to invoke toString() on a non-public type from a different module. This could be seen when attempting to invoke toString() on an unmodifiable list created by Collections.unmodifiableList(...). Doing so resulted in an InaccessibleObjectException. Although users can address that by adding an appropriate --add-opens declaration, such as --add-opens java.base/java.util=ALL-UNNAMED, it is better if applications do not have to add an --add-opens declaration for such use cases in SpEL. The same applies to init methods and destroy methods for beans. This commit therefore introduces a new getPubliclyAccessibleMethodIfPossible() method in ClassUtils which serves as a replacement for getInterfaceMethodIfPossible(). This new method finds the first publicly accessible method in the supplied method's type hierarchy that has a method signature equivalent to the supplied method. If the supplied method is public and declared in a public type, the supplied method will be returned. Otherwise, this method recursively searches the class hierarchy and implemented interfaces for an equivalent method that is public and declared in a public type. If a publicly accessible equivalent method cannot be found, the supplied method will be returned, indicating that no such equivalent method exists. All usage of getInterfaceMethodIfPossible() has been replaced with getPubliclyAccessibleMethodIfPossible() in spring-beans and spring-expression. In addition, getInterfaceMethodIfPossible() has been marked as deprecated in favor of the new method. As a bonus, the introduction of getPubliclyAccessibleMethodIfPossible() allows us to delete a fair amount of obsolete code within the SpEL infrastructure. See gh-29857 Closes gh-33216
- Loading branch information
Showing
15 changed files
with
519 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.