Revisit Assert to avoid single-arg assert methods (with refined messages)
Issue: SPR-15196
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -145,19 +145,19 @@ public abstract class CacheOperation implements BasicOperation {
|
||||
private String condition = "";
|
||||
|
||||
public void setName(String name) {
|
||||
Assert.hasText(name);
|
||||
Assert.hasText(name, "Name must not be empty");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setCacheName(String cacheName) {
|
||||
Assert.hasText(cacheName);
|
||||
Assert.hasText(cacheName, "Cache name must not be empty");
|
||||
this.cacheNames = Collections.singleton(cacheName);
|
||||
}
|
||||
|
||||
public void setCacheNames(String... cacheNames) {
|
||||
this.cacheNames = new LinkedHashSet<>(cacheNames.length);
|
||||
for (String cacheName : cacheNames) {
|
||||
Assert.hasText(cacheName, "Cache name must be non-null if specified");
|
||||
Assert.hasText(cacheName, "Cache name must be non-empty if specified");
|
||||
this.cacheNames.add(cacheName);
|
||||
}
|
||||
}
|
||||
@@ -167,7 +167,7 @@ public abstract class CacheOperation implements BasicOperation {
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
Assert.notNull(key);
|
||||
Assert.notNull(key, "Key must not be null");
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@@ -188,22 +188,22 @@ public abstract class CacheOperation implements BasicOperation {
|
||||
}
|
||||
|
||||
public void setKeyGenerator(String keyGenerator) {
|
||||
Assert.notNull(keyGenerator);
|
||||
Assert.notNull(keyGenerator, "KeyGenerator name must not be null");
|
||||
this.keyGenerator = keyGenerator;
|
||||
}
|
||||
|
||||
public void setCacheManager(String cacheManager) {
|
||||
Assert.notNull(cacheManager);
|
||||
Assert.notNull(cacheManager, "CacheManager name must not be null");
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
public void setCacheResolver(String cacheResolver) {
|
||||
Assert.notNull(this.cacheManager);
|
||||
Assert.notNull(cacheResolver, "CacheResolver name must not be null");
|
||||
this.cacheResolver = cacheResolver;
|
||||
}
|
||||
|
||||
public void setCondition(String condition) {
|
||||
Assert.notNull(condition);
|
||||
Assert.notNull(condition, "Condition must not be null");
|
||||
this.condition = condition;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -143,7 +143,7 @@ class ComponentScanAnnotationParser {
|
||||
switch (filterType) {
|
||||
case ANNOTATION:
|
||||
Assert.isAssignable(Annotation.class, filterClass,
|
||||
"An error occurred while processing a @ComponentScan ANNOTATION type filter: ");
|
||||
"@ComponentScan ANNOTATION type filter requires an annotation type");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
|
||||
typeFilters.add(new AnnotationTypeFilter(annotationType));
|
||||
@@ -153,7 +153,7 @@ class ComponentScanAnnotationParser {
|
||||
break;
|
||||
case CUSTOM:
|
||||
Assert.isAssignable(TypeFilter.class, filterClass,
|
||||
"An error occurred while processing a @ComponentScan CUSTOM type filter: ");
|
||||
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
|
||||
TypeFilter filter = BeanUtils.instantiateClass(filterClass, TypeFilter.class);
|
||||
ParserStrategyUtils.invokeAwareMethods(
|
||||
filter, this.environment, this.resourceLoader, this.registry);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,7 +39,6 @@ import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.LifecycleProcessor;
|
||||
import org.springframework.context.Phased;
|
||||
import org.springframework.context.SmartLifecycle;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Default implementation of the {@link LifecycleProcessor} strategy.
|
||||
@@ -70,7 +69,10 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory);
|
||||
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
|
||||
throw new IllegalArgumentException(
|
||||
"DefaultLifecycleProcessor requires a ConfigurableListableBeanFactory: " + beanFactory);
|
||||
}
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -126,7 +126,7 @@ public class DateTimeFormatterFactory {
|
||||
* @param style two characters from the set {"S", "M", "L", "F", "-"}
|
||||
*/
|
||||
public void setStylePattern(String style) {
|
||||
Assert.isTrue(style != null && style.length() == 2);
|
||||
Assert.isTrue(style != null && style.length() == 2, "Style pattern must consist of two characters");
|
||||
this.dateStyle = convertStyleCharacter(style.charAt(0));
|
||||
this.timeStyle = convertStyleCharacter(style.charAt(1));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,7 +55,7 @@ class WebLogicClassLoaderAdapter {
|
||||
|
||||
|
||||
public WebLogicClassLoaderAdapter(ClassLoader classLoader) {
|
||||
Class<?> wlGenericClassLoaderClass = null;
|
||||
Class<?> wlGenericClassLoaderClass;
|
||||
try {
|
||||
wlGenericClassLoaderClass = classLoader.loadClass(GENERIC_CLASS_LOADER_NAME);
|
||||
this.wlPreProcessorClass = classLoader.loadClass(CLASS_PRE_PROCESSOR_NAME);
|
||||
@@ -66,12 +66,14 @@ class WebLogicClassLoaderAdapter {
|
||||
this.wlGenericClassLoaderConstructor = wlGenericClassLoaderClass.getConstructor(
|
||||
this.getClassFinderMethod.getReturnType(), ClassLoader.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(
|
||||
"Could not initialize WebLogic LoadTimeWeaver because WebLogic 10 API classes are not available", ex);
|
||||
}
|
||||
Assert.isInstanceOf(wlGenericClassLoaderClass, classLoader,
|
||||
"ClassLoader must be instance of [" + wlGenericClassLoaderClass.getName() + "]");
|
||||
if (!wlGenericClassLoaderClass.isInstance(classLoader)) {
|
||||
throw new IllegalArgumentException(
|
||||
"ClassLoader must be an instance of [" + wlGenericClassLoaderClass.getName() + "]: " + classLoader);
|
||||
}
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ class WebLogicClassLoaderAdapter {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("WebLogic addInstanceClassPreProcessor method threw exception", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not invoke WebLogic addInstanceClassPreProcessor method", ex);
|
||||
}
|
||||
}
|
||||
@@ -106,8 +108,9 @@ class WebLogicClassLoaderAdapter {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("WebLogic GenericClassLoader constructor failed", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not construct WebLogic GenericClassLoader", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user