Declare proxyMetadataCache as volatile and ProxiedInterfacesCache fields as final

See gh-30499
This commit is contained in:
Juergen Hoeller
2023-12-22 12:27:03 +01:00
parent 44c652ec98
commit cd11219fa7
2 changed files with 20 additions and 10 deletions

View File

@@ -117,7 +117,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
* @see JdkDynamicAopProxy#JdkDynamicAopProxy(AdvisedSupport) * @see JdkDynamicAopProxy#JdkDynamicAopProxy(AdvisedSupport)
*/ */
@Nullable @Nullable
transient Object proxyMetadataCache; transient volatile Object proxyMetadataCache;
/** /**

View File

@@ -316,31 +316,41 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
*/ */
static final class ProxiedInterfacesCache { static final class ProxiedInterfacesCache {
Class<?>[] proxiedInterfaces; final Class<?>[] proxiedInterfaces;
boolean equalsDefined; final boolean equalsDefined;
boolean hashCodeDefined; final boolean hashCodeDefined;
ProxiedInterfacesCache(AdvisedSupport config) { ProxiedInterfacesCache(AdvisedSupport config) {
this.proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(config, true); this.proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(config, true);
// Find any {@link #equals} or {@link #hashCode} method that may be defined // Find any {@link #equals} or {@link #hashCode} method that may be defined
//on the supplied set of interfaces. // on the supplied set of interfaces.
boolean equalsDefined = false;
boolean hashCodeDefined = false;
for (Class<?> proxiedInterface : this.proxiedInterfaces) { for (Class<?> proxiedInterface : this.proxiedInterfaces) {
Method[] methods = proxiedInterface.getDeclaredMethods(); Method[] methods = proxiedInterface.getDeclaredMethods();
for (Method method : methods) { for (Method method : methods) {
if (AopUtils.isEqualsMethod(method)) { if (AopUtils.isEqualsMethod(method)) {
this.equalsDefined = true; equalsDefined = true;
if (hashCodeDefined) {
break;
}
} }
if (AopUtils.isHashCodeMethod(method)) { if (AopUtils.isHashCodeMethod(method)) {
this.hashCodeDefined = true; hashCodeDefined = true;
} if (equalsDefined) {
if (this.equalsDefined && this.hashCodeDefined) { break;
return; }
} }
} }
if (equalsDefined && hashCodeDefined) {
break;
}
} }
this.equalsDefined = equalsDefined;
this.hashCodeDefined = hashCodeDefined;
} }
} }