From e23ac031ffc49fbdef6e1acb70b220d9093aae97 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 11 Aug 2016 22:56:14 +0200 Subject: [PATCH] Avoid stack overflow in case of chained factory-bean references to FactoryBean class Issue: SPR-14551 (cherry picked from commit 8b5d355) --- .../AbstractAutowireCapableBeanFactory.java | 16 ++++++++++------ ...ractEntityManagerFactoryIntegrationTests.java | 4 ++-- .../orm/jpa/hibernate/hibernate-manager.xml | 6 ++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java index cf25cd5b9a3..f8bd3818830 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -325,8 +325,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac } @Override - public Object resolveDependency(DependencyDescriptor descriptor, String beanName) throws BeansException { - return resolveDependency(descriptor, beanName, null, null); + public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException { + return resolveDependency(descriptor, requestingBeanName, null, null); } @@ -802,10 +802,14 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac if (objectType.value != null) { return objectType.value; } + else { + // No type found for shortcut FactoryBean instance: + // fall back to full creation of the FactoryBean instance. + return super.getTypeForFactoryBean(beanName, mbd); + } } - // No type found - fall back to full creation of the FactoryBean instance. - return super.getTypeForFactoryBean(beanName, mbd); + return null; } /** @@ -824,7 +828,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp; exposedObject = ibp.getEarlyBeanReference(exposedObject, beanName); if (exposedObject == null) { - return exposedObject; + return null; } } } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java index 6850ae7b5a8..90ab41cce7f 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -90,7 +90,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests extends org.s } - static enum Provider { + enum Provider { ECLIPSELINK, HIBERNATE, OPENJPA } diff --git a/spring-orm/src/test/resources/org/springframework/orm/jpa/hibernate/hibernate-manager.xml b/spring-orm/src/test/resources/org/springframework/orm/jpa/hibernate/hibernate-manager.xml index ea7ce16c84b..d6455045576 100644 --- a/spring-orm/src/test/resources/org/springframework/orm/jpa/hibernate/hibernate-manager.xml +++ b/spring-orm/src/test/resources/org/springframework/orm/jpa/hibernate/hibernate-manager.xml @@ -30,4 +30,10 @@ + + + + + +