Skip to content

Commit cd11219

Browse files
committed
Declare proxyMetadataCache as volatile and ProxiedInterfacesCache fields as final
See gh-30499
1 parent 44c652e commit cd11219

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
117117
* @see JdkDynamicAopProxy#JdkDynamicAopProxy(AdvisedSupport)
118118
*/
119119
@Nullable
120-
transient Object proxyMetadataCache;
120+
transient volatile Object proxyMetadataCache;
121121

122122

123123
/**

spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -316,31 +316,41 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound
316316
*/
317317
static final class ProxiedInterfacesCache {
318318

319-
Class<?>[] proxiedInterfaces;
319+
final Class<?>[] proxiedInterfaces;
320320

321-
boolean equalsDefined;
321+
final boolean equalsDefined;
322322

323-
boolean hashCodeDefined;
323+
final boolean hashCodeDefined;
324324

325325
ProxiedInterfacesCache(AdvisedSupport config) {
326326
this.proxiedInterfaces = AopProxyUtils.completeProxiedInterfaces(config, true);
327327

328328
// Find any {@link #equals} or {@link #hashCode} method that may be defined
329-
//on the supplied set of interfaces.
329+
// on the supplied set of interfaces.
330+
boolean equalsDefined = false;
331+
boolean hashCodeDefined = false;
330332
for (Class<?> proxiedInterface : this.proxiedInterfaces) {
331333
Method[] methods = proxiedInterface.getDeclaredMethods();
332334
for (Method method : methods) {
333335
if (AopUtils.isEqualsMethod(method)) {
334-
this.equalsDefined = true;
336+
equalsDefined = true;
337+
if (hashCodeDefined) {
338+
break;
339+
}
335340
}
336341
if (AopUtils.isHashCodeMethod(method)) {
337-
this.hashCodeDefined = true;
338-
}
339-
if (this.equalsDefined && this.hashCodeDefined) {
340-
return;
342+
hashCodeDefined = true;
343+
if (equalsDefined) {
344+
break;
345+
}
341346
}
342347
}
348+
if (equalsDefined && hashCodeDefined) {
349+
break;
350+
}
343351
}
352+
this.equalsDefined = equalsDefined;
353+
this.hashCodeDefined = hashCodeDefined;
344354
}
345355
}
346356

0 commit comments

Comments
 (0)