Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect bridge methods across ApplicationContexts in MethodIntrospector
Prior to this commit, MethodIntrospector failed to properly detect bridge methods for subsequent invocations of selectMethods() with the same targetType and MetadataLookup, if such subsequent invocations occurred after the ApplicationContext had been refreshed. The reason this occurs is due to the following. - Class#getDeclaredMethods() always returns "child copies" of the underlying Method instances -- which means that `equals()` should be used instead of `==` whenever the compared Method instances can come from different sources (such as the static caches mentioned below). - BridgeMethodResolver caches resolved bridge methods in a static cache -- which is never cleared. - ReflectionUtils caches declared methods in a static cache -- which gets cleared when an ApplicationContext is refreshed. Consequently, if you attempt to load an ApplicationContext twice in the same ClassLoader, the second attempt uses the existing, populated cache for bridged methods but a cleared, empty cache for declared methods. This results in new invocations of Class#getDeclaredMethods(), and identity checks with `==` then fail to detect equivalent bridge methods. This commit addresses this by additionally comparing bridge methods using `equals()` in MethodIntrospector.selectMethods(). Note that the `==` checks remain in place as an optimization for when `equals()` is unnecessary. Closes gh-32586 (cherry picked from commit e702733)
- Loading branch information