Author: gnodet
Date: Fri Nov 4 16:49:18 2016
New Revision: 1768066
URL: http://svn.apache.org/viewvc?rev=1768066&view=rev
Log:
[ARIES-960] Improve error message when unable to find a matching constructor /
method
Modified:
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
Modified:
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
URL:
http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java?rev=1768066&r1=1768065&r2=1768066&view=diff
==============================================================================
---
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
(original)
+++
aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BeanRecipe.java
Fri Nov 4 16:49:18 2016
@@ -297,9 +297,9 @@ public class BeanRecipe extends Abstract
throw wrapAsCompDefEx(e);
}
} else if (matches.size() == 0) {
- throw new ComponentDefinitionException("Unable to find a matching
factory method " + factoryMethod + " on class " +
factoryObj.getClass().getName() + " for arguments " + args + " when
instanciating bean " + getName());
+ throw new ComponentDefinitionException("Unable to find a matching
factory method " + factoryMethod + " on class " +
factoryObj.getClass().getName() + " for arguments " + argsToString(args) + "
when instanciating bean " + getName());
} else {
- throw new ComponentDefinitionException("Multiple matching factory
methods " + factoryMethod + " found on class " +
factoryObj.getClass().getName() + " for arguments " + args + " when
instanciating bean " + getName() + ": " + matches.keySet());
+ throw new ComponentDefinitionException("Multiple matching factory
methods " + factoryMethod + " found on class " +
factoryObj.getClass().getName() + " for arguments " + argsToString(args) + "
when instanciating bean " + getName() + ": " + matches.keySet());
}
}
@@ -331,9 +331,9 @@ public class BeanRecipe extends Abstract
throw wrapAsCompDefEx(e);
}
} else if (matches.size() == 0) {
- throw new ComponentDefinitionException("Unable to find a matching
factory method " + factoryMethod + " on class " + getTypeName() + " for
arguments " + args + " when instanciating bean " + getName());
+ throw new ComponentDefinitionException("Unable to find a matching
factory method " + factoryMethod + " on class " + getTypeName() + " for
arguments " + argsToString(args) + " when instanciating bean " + getName());
} else {
- throw new ComponentDefinitionException("Multiple matching factory
methods " + factoryMethod + " found on class " + getTypeName() + " for
arguments " + args + " when instanciating bean " + getName() + ": " +
matches.keySet());
+ throw new ComponentDefinitionException("Multiple matching factory
methods " + factoryMethod + " found on class " + getTypeName() + " for
arguments " + argsToString(args) + " when instanciating bean " + getName() + ":
" + matches.keySet());
}
}
@@ -351,9 +351,9 @@ public class BeanRecipe extends Abstract
throw wrapAsCompDefEx(e);
}
} else if (matches.size() == 0) {
- throw new ComponentDefinitionException("Unable to find a matching
constructor on class " + getTypeName() + " for arguments " + args + " when
instanciating bean " + getName());
+ throw new ComponentDefinitionException("Unable to find a matching
constructor on class " + getTypeName() + " for arguments " + argsToString(args)
+ " when instanciating bean " + getName());
} else {
- throw new ComponentDefinitionException("Multiple matching
constructors found on class " + getTypeName() + " for arguments " + args + "
when instanciating bean " + getName() + ": " + matches.keySet());
+ throw new ComponentDefinitionException("Multiple matching
constructors found on class " + getTypeName() + " for arguments " +
argsToString(args) + " when instanciating bean " + getName() + ": " +
matches.keySet());
}
}
@@ -402,11 +402,11 @@ public class BeanRecipe extends Abstract
found = false;
break;
}
- //If the arg is an Unwrappered bean then we need to do the
assignment check against the
- //unwrappered bean itself.
+ // If the arg is an Unwrappered bean then we need to do
the assignment
+ // check against the unwrappered bean itself.
Object arg = args.get(i);
Object argToTest = arg;
- if(arg instanceof UnwrapperedBeanHolder)
+ if (arg instanceof UnwrapperedBeanHolder)
argToTest =
((UnwrapperedBeanHolder)arg).unwrapperedBean;
if (!AggregateConverter.isAssignable(argToTest, argType)) {
found = false;
@@ -549,11 +549,11 @@ public class BeanRecipe extends Abstract
found = false;
break;
}
- //If the arg is an Unwrappered bean then we need to do the
assignment check against the
- //unwrappered bean itself.
+ // If the arg is an Unwrappered bean then we need to do
the assignment
+ // check against the unwrappered bean itself.
Object arg = args.get(i);
Object argToTest = arg;
- if(arg instanceof UnwrapperedBeanHolder)
+ if (arg instanceof UnwrapperedBeanHolder)
argToTest =
((UnwrapperedBeanHolder)arg).unwrapperedBean;
if (!AggregateConverter.isAssignable(argToTest, argType)) {
found = false;
@@ -983,6 +983,24 @@ public class BeanRecipe extends Abstract
private Object newInstance(Constructor constructor, Object... args) throws
Exception {
return
ReflectionUtils.newInstance(blueprintContainer.getAccessControlContext(),
constructor, args);
}
+
+ private String argsToString(List<Object> args) {
+ Iterator<Object> it = args.iterator();
+ if (!it.hasNext())
+ return "[]";
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (;;) {
+ Object e = it.next();
+ if (e instanceof UnwrapperedBeanHolder) {
+ e = ((UnwrapperedBeanHolder) e).unwrapperedBean;
+ }
+ sb.append(e).append(" (").append(e.getClass()).append(")");
+ if (!it.hasNext())
+ return sb.append(']').toString();
+ sb.append(',').append(' ');
+ }
+ }
private static Object UNMATCHED = new Object();