From b8e663c531a0e1e628095cba37a74efaa40a1419 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 7 Feb 2019 15:57:44 +0100 Subject: [PATCH] AbstractAutoProxyCreator ignores unused early proxy references Closes gh-22370 --- .../framework/autoproxy/AbstractAutoProxyCreator.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java index 05eb217803..6e6aae64ba 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -133,7 +133,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport private final Set targetSourcedBeans = Collections.newSetFromMap(new ConcurrentHashMap<>(16)); - private final Set earlyProxyReferences = Collections.newSetFromMap(new ConcurrentHashMap<>(16)); + private final Map earlyProxyReferences = new ConcurrentHashMap<>(16); private final Map> proxyTypes = new ConcurrentHashMap<>(16); @@ -236,9 +236,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport @Override public Object getEarlyBeanReference(Object bean, String beanName) { Object cacheKey = getCacheKey(bean.getClass(), beanName); - if (!this.earlyProxyReferences.contains(cacheKey)) { - this.earlyProxyReferences.add(cacheKey); - } + this.earlyProxyReferences.put(cacheKey, bean); return wrapIfNecessary(bean, beanName, cacheKey); } @@ -297,7 +295,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) { if (bean != null) { Object cacheKey = getCacheKey(bean.getClass(), beanName); - if (!this.earlyProxyReferences.contains(cacheKey)) { + if (this.earlyProxyReferences.remove(cacheKey) != bean) { return wrapIfNecessary(bean, beanName, cacheKey); } }