Favor Class#getTypeName over ClassUtils#getQualifiedName where feasible

This commit is contained in:
Sam Brannen
2026-04-08 13:27:52 +02:00
parent c17f25f939
commit 8566e7bf55
7 changed files with 9 additions and 17 deletions
@@ -20,7 +20,6 @@ import java.lang.reflect.Type;
import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
import org.springframework.util.ClassUtils;
/**
* Thrown when a bean doesn't match the expected type.
@@ -63,7 +62,7 @@ public class BeanNotOfRequiredTypeException extends BeansException {
*/
public BeanNotOfRequiredTypeException(String beanName, Type requiredType, Class<?> actualType) {
super("Bean named '" + beanName + "' is expected to be of type '" + requiredType.getTypeName() +
"' but was actually of type '" + ClassUtils.getQualifiedName(actualType) + "'");
"' but was actually of type '" + actualType.getTypeName() + "'");
this.beanName = beanName;
this.genericRequiredType = requiredType;
this.actualType = actualType;
@@ -45,7 +45,7 @@ public interface AutowiredArguments {
Object value = getObject(index);
if (!ClassUtils.isAssignableValue(requiredType, value)) {
throw new IllegalArgumentException("Argument type mismatch: expected '" +
ClassUtils.getQualifiedName(requiredType) + "' for value [" + value + "]");
requiredType.getTypeName() + "' for value [" + value + "]");
}
return (T) value;
}
@@ -426,7 +426,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
catch (TypeMismatchException ex) {
if (logger.isTraceEnabled()) {
logger.trace("Failed to convert bean '" + name + "' to required type '" +
ClassUtils.getQualifiedName(requiredType) + "'", ex);
requiredType.getTypeName() + "'", ex);
}
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
@@ -84,8 +84,8 @@ public class ClassArrayEditor extends PropertyEditorSupport {
return "";
}
StringJoiner sj = new StringJoiner(",");
for (Class<?> klass : classes) {
sj.add(ClassUtils.getQualifiedName(klass));
for (Class<?> clazz : classes) {
sj.add(clazz.getTypeName());
}
return sj.toString();
}
@@ -72,12 +72,7 @@ public class ClassEditor extends PropertyEditorSupport {
@Override
public String getAsText() {
Class<?> clazz = (Class<?>) getValue();
if (clazz != null) {
return ClassUtils.getQualifiedName(clazz);
}
else {
return "";
}
return (clazz != null ? clazz.getTypeName() : "");
}
}
@@ -42,7 +42,6 @@ import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
@@ -342,7 +341,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
Object value = getColumnValue(rs, index, pd);
if (rowNumber == 0 && logger.isDebugEnabled()) {
logger.debug("Mapping column '" + column + "' to property '" + pd.getName() +
"' of type '" + ClassUtils.getQualifiedName(pd.getPropertyType()) + "'");
"' of type '" + pd.getPropertyType().getTypeName() + "'");
}
try {
bw.setPropertyValue(pd.getName(), value);
@@ -350,7 +349,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
catch (TypeMismatchException ex) {
if (value == null && isPrimitivesDefaultedForNullValue()) {
if (logger.isDebugEnabled()) {
String propertyType = ClassUtils.getQualifiedName(pd.getPropertyType());
String propertyType = pd.getPropertyType().getTypeName();
logger.debug("""
Ignoring intercepted TypeMismatchException for row %d and column '%s' \
with null value when setting property '%s' of type '%s' on object: %s"
@@ -32,7 +32,6 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
@@ -464,7 +463,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
private String appendPayload(Object payload) {
if (payload.getClass() != byte[].class) {
throw new IllegalStateException(
"Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass()));
"Expected byte array payload but got: " + payload.getClass().getTypeName());
}
byte[] bytes = (byte[]) payload;
MimeType mimeType = getContentType();