revised lenient constructor resolution (follow-up to SPR-5816)

This commit is contained in:
Juergen Hoeller
2009-07-16 17:22:03 +00:00
parent 7eabd2da56
commit 8e2797153b
3 changed files with 26 additions and 9 deletions

View File

@@ -573,20 +573,15 @@ class ConstructorResolver {
(ConstructorArgumentValues.ValueHolder) valueHolder.getSource();
Object originalValue = valueHolder.getValue();
Object sourceValue = sourceHolder.getValue();
Object convertedValue;
if (valueHolder.isConverted()) {
Object convertedValue = valueHolder.getConvertedValue();
args.rawArguments[paramIndex] =
(mbd.isLenientConstructorResolution() ? originalValue : convertedValue);
args.arguments[paramIndex] = convertedValue;
convertedValue = valueHolder.getConvertedValue();
args.preparedArguments[paramIndex] = convertedValue;
}
else {
try {
Object convertedValue = converter.convertIfNecessary(originalValue, paramType,
convertedValue = converter.convertIfNecessary(originalValue, paramType,
MethodParameter.forMethodOrConstructor(methodOrCtor, paramIndex));
args.rawArguments[paramIndex] =
(mbd.isLenientConstructorResolution() ? originalValue : convertedValue);
args.arguments[paramIndex] = convertedValue;
if (originalValue == sourceValue || sourceValue instanceof TypedStringValue) {
// Either a converted value or still the original one: store converted value.
sourceHolder.setConvertedValue(convertedValue);
@@ -605,6 +600,15 @@ class ConstructorResolver {
"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
}
}
args.arguments[paramIndex] = convertedValue;
if (mbd.isLenientConstructorResolution()) {
args.rawArguments[paramIndex] = originalValue;
}
else {
args.rawArguments[paramIndex] =
((sourceValue instanceof TypedStringValue && !((TypedStringValue) sourceValue).hasTargetType()) ?
convertedValue : originalValue);
}
}
else {
// No explicit match found: we're either supposed to autowire or