adapted to changes in non-lenient mode

This commit is contained in:
Juergen Hoeller 2009-08-27 10:45:46 +00:00
parent 636c4901c0
commit 904c2358cd
2 changed files with 5 additions and 41 deletions

View File

@ -259,14 +259,12 @@ class ConstructorResolver {
} }
try { try {
Object beanInstance = null; Object beanInstance;
if (System.getSecurityManager() != null) { if (System.getSecurityManager() != null) {
final Constructor ctorToUse = constructorToUse; final Constructor ctorToUse = constructorToUse;
final Object[] argumentsToUse = argsToUse; final Object[] argumentsToUse = argsToUse;
beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() { beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() { public Object run() {
return beanFactory.getInstantiationStrategy().instantiate( return beanFactory.getInstantiationStrategy().instantiate(
mbd, beanName, beanFactory, ctorToUse, argumentsToUse); mbd, beanName, beanFactory, ctorToUse, argumentsToUse);
@ -389,7 +387,6 @@ class ConstructorResolver {
final Class factoryClazz = factoryClass; final Class factoryClazz = factoryClass;
if (System.getSecurityManager() != null) { if (System.getSecurityManager() != null) {
rawCandidates = AccessController.doPrivileged(new PrivilegedAction<Method[]>() { rawCandidates = AccessController.doPrivileged(new PrivilegedAction<Method[]>() {
public Method[] run() { public Method[] run() {
return (mbd.isNonPublicAccessAllowed() ? return (mbd.isNonPublicAccessAllowed() ?
@ -416,7 +413,7 @@ class ConstructorResolver {
ConstructorArgumentValues resolvedValues = null; ConstructorArgumentValues resolvedValues = null;
boolean autowiring = (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR); boolean autowiring = (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
int minTypeDiffWeight = Integer.MAX_VALUE; int minTypeDiffWeight = Integer.MAX_VALUE;
Set<Method> ambiguousFactoryMethods = null; Set<Method> ambiguousFactoryMethods = null;
int minNrOfArgs; int minNrOfArgs;
if (explicitArgs != null) { if (explicitArgs != null) {
@ -526,16 +523,13 @@ class ConstructorResolver {
} }
try { try {
Object beanInstance;
Object beanInstance = null;
if (System.getSecurityManager() != null) { if (System.getSecurityManager() != null) {
final Object fb = factoryBean; final Object fb = factoryBean;
final Method factoryMethod = factoryMethodToUse; final Method factoryMethod = factoryMethodToUse;
final Object[] args = argsToUse; final Object[] args = argsToUse;
beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() { beanInstance = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() { public Object run() {
return beanFactory.getInstantiationStrategy().instantiate( return beanFactory.getInstantiationStrategy().instantiate(
mbd, beanName, beanFactory, fb, factoryMethod, args); mbd, beanName, beanFactory, fb, factoryMethod, args);

View File

@ -1365,36 +1365,6 @@ public final class XmlBeanFactoryTests {
assertEquals(Boolean.TRUE, bean.boolean2); assertEquals(Boolean.TRUE, bean.boolean2);
} }
public @Test void testDoubleBooleanNoType() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("beanWithDoubleBooleanNoType");
bd.setLenientConstructorResolution(false);
try {
xbf.getBean("beanWithDoubleBooleanNoType");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
ex.printStackTrace();
assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous"));
}
}
public @Test void testDoubleBooleanNoTypeFactoryMethod() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("beanWithDoubleBooleanNoTypeFactoryMethod");
bd.setLenientConstructorResolution(false);
try {
xbf.getBean("beanWithDoubleBooleanNoTypeFactoryMethod");
fail("Should have thrown BeanCreationException");
}
catch (BeanCreationException ex) {
// expected
ex.printStackTrace();
assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous"));
}
}
public @Test void testLenientDependencyMatching() { public @Test void testLenientDependencyMatching() {
XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT); XmlBeanFactory xbf = new XmlBeanFactory(CONSTRUCTOR_ARG_CONTEXT);
LenientDependencyTestBean bean = (LenientDependencyTestBean) xbf.getBean("lenientDependencyTestBean"); LenientDependencyTestBean bean = (LenientDependencyTestBean) xbf.getBean("lenientDependencyTestBean");