Add more @Nullable parameters based on null usage

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-31 21:35:52 +02:00
parent f9b319d3ba
commit 1f28825f9d
219 changed files with 441 additions and 355 deletions

View File

@@ -458,7 +458,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
}
private void logInvalidating(CacheOperationContext context, CacheEvictOperation operation, Object key) {
private void logInvalidating(CacheOperationContext context, CacheEvictOperation operation, @Nullable Object key) {
if (logger.isTraceEnabled()) {
logger.trace("Invalidating " + (key != null ? "cache key [" + key + "]" : "entire cache") +
" for operation " + operation + " on method " + context.metadata.method);

View File

@@ -53,7 +53,7 @@ public interface MessageSource {
* otherwise the default message passed as a parameter
* @see java.text.MessageFormat
*/
String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale);
String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale);
/**
* Try to resolve the message. Treat as an error if the message can't be found.

View File

@@ -18,6 +18,7 @@ package org.springframework.context;
import org.springframework.beans.factory.Aware;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
/**
* Interface to be implemented by any object that wishes to be notified of
@@ -73,6 +74,6 @@ public interface ResourceLoaderAware extends Aware {
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.core.io.support.ResourcePatternUtils#getResourcePatternResolver
*/
void setResourceLoader(ResourceLoader resourceLoader);
void setResourceLoader(@Nullable ResourceLoader resourceLoader);
}

View File

@@ -210,7 +210,7 @@ public class AnnotatedBeanDefinitionReader {
* factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
* @since 5.0
*/
<T> void doRegisterBean(Class<T> annotatedClass, @Nullable Supplier<T> instanceSupplier, String name,
<T> void doRegisterBean(Class<T> annotatedClass, @Nullable Supplier<T> instanceSupplier, @Nullable String name,
@Nullable Class<? extends Annotation>[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) {
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);

View File

@@ -214,7 +214,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
}
@Override
public <T> void registerBean(@Nullable String beanName, @Nullable Class<T> beanClass, Supplier<T> supplier,
public <T> void registerBean(@Nullable String beanName, @Nullable Class<T> beanClass, @Nullable Supplier<T> supplier,
BeanDefinitionCustomizer... customizers) {
this.reader.doRegisterBean(beanClass, supplier, beanName, null, customizers);

View File

@@ -252,7 +252,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
* @see org.springframework.core.io.support.PathMatchingResourcePatternResolver
*/
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
this.resourcePatternResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
this.metadataReaderFactory = new CachingMetadataReaderFactory(resourceLoader);
this.componentsIndex = CandidateComponentsIndexLoader.loadIndex(this.resourcePatternResolver.getClassLoader());

View File

@@ -193,7 +193,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
}
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
Assert.notNull(resourceLoader, "ResourceLoader must not be null");
this.resourceLoader = resourceLoader;
if (!this.setMetadataReaderFactoryCalled) {

View File

@@ -208,7 +208,7 @@ public abstract class AbstractApplicationEventMulticaster
* @return the pre-filtered list of application listeners for the given event and source type
*/
private Collection<ApplicationListener<?>> retrieveApplicationListeners(
ResolvableType eventType, Class<?> sourceType, ListenerRetriever retriever) {
ResolvableType eventType, Class<?> sourceType, @Nullable ListenerRetriever retriever) {
LinkedList<ApplicationListener<?>> allListeners = new LinkedList<>();
Set<ApplicationListener<?>> listeners;

View File

@@ -367,7 +367,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
* @param eventType the resolved event type, if known
* @since 4.2
*/
protected void publishEvent(Object event, ResolvableType eventType) {
protected void publishEvent(Object event, @Nullable ResolvableType eventType) {
Assert.notNull(event, "Event must not be null");
if (logger.isTraceEnabled()) {
logger.trace("Publishing event in " + getDisplayName() + ": " + event);
@@ -1250,7 +1250,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
//---------------------------------------------------------------------
@Override
public String getMessage(String code, @Nullable Object args[], String defaultMessage, Locale locale) {
public String getMessage(String code, @Nullable Object args[], @Nullable String defaultMessage, Locale locale) {
return getMessageSource().getMessage(code, args, defaultMessage, locale);
}

View File

@@ -134,7 +134,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
@Override
public final String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale) {
public final String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
String msg = getMessageInternal(code, args, locale);
if (msg != null) {
return msg;

View File

@@ -52,7 +52,7 @@ public class DelegatingMessageSource extends MessageSourceSupport implements Hie
@Override
public String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale) {
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
if (this.parentMessageSource != null) {
return this.parentMessageSource.getMessage(code, args, defaultMessage, locale);
}

View File

@@ -419,7 +419,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
* factory's {@link BeanDefinition}, e.g. setting a lazy-init or primary flag
* @since 5.0
*/
public <T> void registerBean(@Nullable String beanName, @Nullable Class<T> beanClass, Supplier<T> supplier,
public <T> void registerBean(@Nullable String beanName, @Nullable Class<T> beanClass, @Nullable Supplier<T> supplier,
BeanDefinitionCustomizer... customizers) {
Assert.isTrue(beanName != null || beanClass != null, "Either bean name or bean class must be specified");

View File

@@ -162,7 +162,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
* @see org.springframework.context.ResourceLoaderAware
*/
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
}

View File

@@ -22,6 +22,8 @@ import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.List;
import org.springframework.lang.Nullable;
/**
* ClassFileTransformer-based weaver, allowing for a list of transformers to be
* applied on a class byte array. Normally used inside class loaders.
@@ -88,7 +90,7 @@ public class WeavingTransformer {
* @param pd protection domain to be used (can be null)
* @return (possibly transformed) class byte definition
*/
public byte[] transformIfNecessary(String className, String internalName, byte[] bytes, ProtectionDomain pd) {
public byte[] transformIfNecessary(String className, String internalName, byte[] bytes, @Nullable ProtectionDomain pd) {
byte[] result = bytes;
for (ClassFileTransformer cft : this.transformers) {
try {

View File

@@ -749,7 +749,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
* @throws javax.management.MalformedObjectNameException
* if the retrieved {@code ObjectName} is malformed
*/
protected ObjectName getObjectName(Object bean, String beanKey) throws MalformedObjectNameException {
protected ObjectName getObjectName(Object bean, @Nullable String beanKey) throws MalformedObjectNameException {
if (bean instanceof SelfNaming) {
return ((SelfNaming) bean).getObjectName();
}

View File

@@ -20,6 +20,7 @@ import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.springframework.core.SpringProperties;
import org.springframework.lang.Nullable;
/**
* {@link JndiLocatorSupport} subclass with public lookup methods,
@@ -59,7 +60,7 @@ public class JndiLocatorDelegate extends JndiLocatorSupport {
}
@Override
public <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException {
public <T> T lookup(String jndiName, @Nullable Class<T> requiredType) throws NamingException {
return super.lookup(jndiName, requiredType);
}

View File

@@ -18,6 +18,7 @@ package org.springframework.jndi;
import javax.naming.NamingException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -87,7 +88,7 @@ public abstract class JndiLocatorSupport extends JndiAccessor {
* @throws NamingException if the JNDI lookup failed
* @see #setResourceRef
*/
protected <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException {
protected <T> T lookup(String jndiName, @Nullable Class<T> requiredType) throws NamingException {
Assert.notNull(jndiName, "'jndiName' must not be null");
String convertedName = convertJndiName(jndiName);
T jndiObject;

View File

@@ -206,7 +206,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
@SuppressWarnings("unchecked")
private <T> T doGetSingleton(String name, Class<T> requiredType) throws NamingException {
private <T> T doGetSingleton(String name, @Nullable Class<T> requiredType) throws NamingException {
synchronized (this.singletonObjects) {
if (this.singletonObjects.containsKey(name)) {
Object jndiObject = this.singletonObjects.get(name);

View File

@@ -20,6 +20,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.springframework.lang.Nullable;
import org.springframework.util.concurrent.FailureCallback;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
@@ -54,7 +55,7 @@ public class AsyncResult<V> implements ListenableFuture<V> {
* Create a new AsyncResult holder.
* @param value the value to pass through
*/
public AsyncResult(V value) {
public AsyncResult(@Nullable V value) {
this(value, null);
}
@@ -62,7 +63,7 @@ public class AsyncResult<V> implements ListenableFuture<V> {
* Create a new AsyncResult holder.
* @param value the value to pass through
*/
private AsyncResult(V value, ExecutionException ex) {
private AsyncResult(@Nullable V value, @Nullable ExecutionException ex) {
this.value = value;
this.executionException = ex;
}

View File

@@ -28,6 +28,7 @@ import javax.enterprise.concurrent.ManagedTask;
import org.springframework.core.task.AsyncListenableTaskExecutor;
import org.springframework.core.task.TaskDecorator;
import org.springframework.core.task.support.TaskExecutorAdapter;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.SchedulingAwareRunnable;
import org.springframework.scheduling.SchedulingTaskExecutor;
import org.springframework.util.ClassUtils;
@@ -105,7 +106,7 @@ public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, Sche
* <p>Autodetects a JSR-236 {@link javax.enterprise.concurrent.ManagedExecutorService}
* in order to expose {@link javax.enterprise.concurrent.ManagedTask} adapters for it.
*/
public final void setConcurrentExecutor(Executor concurrentExecutor) {
public final void setConcurrentExecutor(@Nullable Executor concurrentExecutor) {
if (concurrentExecutor != null) {
this.concurrentExecutor = concurrentExecutor;
if (managedExecutorServiceClass != null && managedExecutorServiceClass.isInstance(concurrentExecutor)) {

View File

@@ -85,7 +85,7 @@ public abstract class BshScriptUtils {
* @return the scripted Java object
* @throws EvalError in case of BeanShell parsing failure
*/
public static Object createBshObject(String scriptSource, @Nullable Class<?>[] scriptInterfaces, ClassLoader classLoader)
public static Object createBshObject(String scriptSource, @Nullable Class<?>[] scriptInterfaces, @Nullable ClassLoader classLoader)
throws EvalError {
Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader);

View File

@@ -228,7 +228,7 @@ public class ScriptFactoryPostProcessor extends InstantiationAwareBeanPostProces
}
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
public void setResourceLoader(@Nullable ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

View File

@@ -92,7 +92,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public void reject(String errorCode, @Nullable Object[] errorArgs, String defaultMessage) {
public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) {
addError(new ObjectError(getObjectName(), resolveMessageCodes(errorCode), errorArgs, defaultMessage));
}

View File

@@ -115,7 +115,7 @@ public class BindException extends Exception implements BindingResult {
}
@Override
public void reject(String errorCode, @Nullable Object[] errorArgs, String defaultMessage) {
public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) {
this.bindingResult.reject(errorCode, errorArgs, defaultMessage);
}

View File

@@ -164,13 +164,13 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
return StringUtils.toStringArray(codeList);
}
private void addCodes(Collection<String> codeList, String errorCode, String objectName, Iterable<String> fields) {
private void addCodes(Collection<String> codeList, String errorCode, @Nullable String objectName, Iterable<String> fields) {
for (String field : fields) {
addCode(codeList, errorCode, objectName, field);
}
}
private void addCode(Collection<String> codeList, String errorCode, String objectName, String field) {
private void addCode(Collection<String> codeList, String errorCode, @Nullable String objectName, @Nullable String field) {
codeList.add(postProcessMessageCode(this.formatter.format(errorCode, objectName, field)));
}

View File

@@ -121,7 +121,7 @@ public interface Errors {
* (can be {@code null})
* @param defaultMessage fallback default message
*/
void reject(String errorCode, @Nullable Object[] errorArgs, String defaultMessage);
void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage);
/**
* Register a field error for the specified field of the current object

View File

@@ -160,7 +160,7 @@ public abstract class ValidationUtils {
* @param defaultMessage fallback default message
*/
public static void rejectIfEmpty(
Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, String defaultMessage) {
Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) {
Assert.notNull(errors, "Errors object must not be null");
Object value = errors.getFieldValue(field);
@@ -240,7 +240,7 @@ public abstract class ValidationUtils {
* @param defaultMessage fallback default message
*/
public static void rejectIfEmptyOrWhitespace(
Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, String defaultMessage) {
Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) {
Assert.notNull(errors, "Errors object must not be null");
Object value = errors.getFieldValue(field);