Backported exception message refinements from 4.2.x

This commit is contained in:
Juergen Hoeller
2015-11-30 12:24:38 +01:00
parent 6c4f0a4d9f
commit a730b6e1aa
3 changed files with 15 additions and 10 deletions

View File

@@ -331,7 +331,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
String scopeName = mbd.getScope(); String scopeName = mbd.getScope();
final Scope scope = this.scopes.get(scopeName); final Scope scope = this.scopes.get(scopeName);
if (scope == null) { if (scope == null) {
throw new IllegalStateException("No Scope registered for scope '" + scopeName + "'"); throw new IllegalStateException("No Scope registered for scope name '" + scopeName + "'");
} }
try { try {
Object scopedInstance = scope.get(beanName, new ObjectFactory<Object>() { Object scopedInstance = scope.get(beanName, new ObjectFactory<Object>() {
@@ -350,8 +350,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
} }
catch (IllegalStateException ex) { catch (IllegalStateException ex) {
throw new BeanCreationException(beanName, throw new BeanCreationException(beanName,
"Scope '" + scopeName + "' is not active for the current thread; " + "Scope '" + scopeName + "' is not active for the current thread; consider " +
"consider defining a scoped proxy for this bean if you intend to refer to it from a singleton", "defining a scoped proxy for this bean if you intend to refer to it from a singleton",
ex); ex);
} }
} }
@@ -1334,6 +1334,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
private Class<?> doResolveBeanClass(RootBeanDefinition mbd, Class<?>... typesToMatch) throws ClassNotFoundException { private Class<?> doResolveBeanClass(RootBeanDefinition mbd, Class<?>... typesToMatch) throws ClassNotFoundException {
if (!ObjectUtils.isEmpty(typesToMatch)) { if (!ObjectUtils.isEmpty(typesToMatch)) {
// When just doing type checks (i.e. not creating an actual instance yet),
// use the specified temporary class loader (e.g. in a weaving scenario).
ClassLoader tempClassLoader = getTempClassLoader(); ClassLoader tempClassLoader = getTempClassLoader();
if (tempClassLoader != null) { if (tempClassLoader != null) {
if (tempClassLoader instanceof DecoratingClassLoader) { if (tempClassLoader instanceof DecoratingClassLoader) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -43,7 +43,8 @@ public final class ConversionFailedException extends ConversionException {
* @param cause the cause of the conversion failure * @param cause the cause of the conversion failure
*/ */
public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) { public ConversionFailedException(TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) {
super("Failed to convert from type " + sourceType + " to type " + targetType + " for value '" + ObjectUtils.nullSafeToString(value) + "'", cause); super("Failed to convert from type [" + sourceType + "] to type [" + targetType +
"] for value '" + ObjectUtils.nullSafeToString(value) + "'", cause);
this.sourceType = sourceType; this.sourceType = sourceType;
this.targetType = targetType; this.targetType = targetType;
this.value = value; this.value = value;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2010 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -17,9 +17,11 @@
package org.springframework.core.convert; package org.springframework.core.convert;
/** /**
* Thrown when a suitable converter could not be found in a conversion service. * Exception to be thrown when a suitable converter could not be found
* in a given conversion service.
* *
* @author Keith Donald * @author Keith Donald
* @author Juergen Hoeller
* @since 3.0 * @since 3.0
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
@@ -36,21 +38,21 @@ public final class ConverterNotFoundException extends ConversionException {
* @param targetType the target type requested to convert to * @param targetType the target type requested to convert to
*/ */
public ConverterNotFoundException(TypeDescriptor sourceType, TypeDescriptor targetType) { public ConverterNotFoundException(TypeDescriptor sourceType, TypeDescriptor targetType) {
super("No converter found capable of converting from type " + sourceType + " to type " + targetType); super("No converter found capable of converting from type [" + sourceType + "] to type [" + targetType + "]");
this.sourceType = sourceType; this.sourceType = sourceType;
this.targetType = targetType; this.targetType = targetType;
} }
/** /**
* Returns the source type that was requested to convert from. * Return the source type that was requested to convert from.
*/ */
public TypeDescriptor getSourceType() { public TypeDescriptor getSourceType() {
return this.sourceType; return this.sourceType;
} }
/** /**
* Returns the target type that was requested to convert to. * Return the target type that was requested to convert to.
*/ */
public TypeDescriptor getTargetType() { public TypeDescriptor getTargetType() {
return this.targetType; return this.targetType;