Introduce null-safety of Spring Framework API

This commit introduces 2 new @Nullable and @NonNullApi
annotations that leverage JSR 305 (dormant but available via
Findbugs jsr305 dependency and already used by libraries
like OkHttp) meta-annotations to specify explicitly
null-safety of Spring Framework parameters and return values.

In order to avoid adding too much annotations, the
default is set at package level with @NonNullApi and
@Nullable annotations are added when needed at parameter or
return value level. These annotations are intended to be used
on Spring Framework itself but also by other Spring projects.

@Nullable annotations have been introduced based on Javadoc
and search of patterns like "return null;". It is expected that
nullability of Spring Framework API will be polished with
complementary commits.

In practice, this will make the whole Spring Framework API
null-safe for Kotlin projects (when KT-10942 will be fixed)
since Kotlin will be able to leverage these annotations to
know if a parameter or a return value is nullable or not. But
this is also useful for Java developers as well since IntelliJ
IDEA, for example, also understands these annotations to
generate warnings when unsafe nullable usages are detected.

Issue: SPR-15540
This commit is contained in:
Sebastien Deleuze
2017-05-27 08:14:59 +02:00
parent 2d37c966b2
commit 87598f48e4
1315 changed files with 4831 additions and 963 deletions

View File

@@ -18,6 +18,8 @@ package org.springframework.cache;
import java.util.concurrent.Callable;
import org.springframework.lang.Nullable;
/**
* Interface that defines common cache operations.
*
@@ -54,7 +56,8 @@ public interface Cache {
* returned means that the cache contains no mapping for this key.
* @see #get(Object, Class)
*/
ValueWrapper get(Object key);
@Nullable
ValueWrapper get(@Nullable Object key);
/**
* Return the value to which this cache maps the specified key,
@@ -74,7 +77,8 @@ public interface Cache {
* @since 4.0
* @see #get(Object)
*/
<T> T get(Object key, Class<T> type);
@Nullable
<T> T get(@Nullable Object key, Class<T> type);
/**
* Return the value to which this cache maps the specified key, obtaining
@@ -91,7 +95,8 @@ public interface Cache {
* @throws ValueRetrievalException if the {@code valueLoader} throws an exception
* @since 4.3
*/
<T> T get(Object key, Callable<T> valueLoader);
@Nullable
<T> T get(@Nullable Object key, Callable<T> valueLoader);
/**
* Associate the specified value with the specified key in this cache.
@@ -100,7 +105,7 @@ public interface Cache {
* @param key the key with which the specified value is to be associated
* @param value the value to be associated with the specified key
*/
void put(Object key, Object value);
void put(@Nullable Object key, @Nullable Object value);
/**
* Atomically associate the specified value with the specified key in this cache
@@ -128,13 +133,14 @@ public interface Cache {
* an indicator that the given {@code value} has been associated with the key.
* @since 4.1
*/
ValueWrapper putIfAbsent(Object key, Object value);
@Nullable
ValueWrapper putIfAbsent(@Nullable Object key, @Nullable Object value);
/**
* Evict the mapping for this key from this cache if it is present.
* @param key the key whose mapping is to be removed from the cache
*/
void evict(Object key);
void evict(@Nullable Object key);
/**
* Remove all mappings from the cache.
@@ -151,7 +157,7 @@ public interface Cache {
/**
* Return the actual value in the cache.
*/
Object get();
@Nullable Object get();
}
@@ -165,11 +171,12 @@ public interface Cache {
private final Object key;
public ValueRetrievalException(Object key, Callable<?> loader, Throwable ex) {
public ValueRetrievalException(@Nullable Object key, Callable<?> loader, Throwable ex) {
super(String.format("Value for key '%s' could not be loaded using '%s'", key, loader), ex);
this.key = key;
}
@Nullable
public Object getKey() {
return this.key;
}

View File

@@ -18,6 +18,8 @@ package org.springframework.cache;
import java.util.Collection;
import org.springframework.lang.Nullable;
/**
* Spring's central cache manager SPI.
* Allows for retrieving named {@link Cache} regions.
@@ -32,6 +34,7 @@ public interface CacheManager {
* @param name the cache identifier (must not be {@code null})
* @return the associated cache, or {@code null} if none found
*/
@Nullable
Cache getCache(String name);
/**

View File

@@ -26,6 +26,7 @@ import java.util.Set;
import org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource;
import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -135,6 +136,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
* @param provider the cache operation provider to use
* @return the configured caching operations, or {@code null} if none found
*/
@Nullable
protected Collection<CacheOperation> determineCacheOperations(CacheOperationProvider provider) {
Collection<CacheOperation> ops = null;
for (CacheAnnotationParser annotationParser : this.annotationParsers) {
@@ -189,6 +191,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
* @param parser the parser to use
* @return the cache operations, or {@code null} if none found
*/
@Nullable
Collection<CacheOperation> getCacheOperations(CacheAnnotationParser parser);
}

View File

@@ -20,6 +20,7 @@ import java.lang.reflect.Method;
import java.util.Collection;
import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.lang.Nullable;
/**
* Strategy interface for parsing known caching annotation types.
@@ -44,6 +45,7 @@ public interface CacheAnnotationParser {
* or {@code null} if none was found
* @see AnnotationCacheOperationSource#findCacheOperations(Class)
*/
@Nullable
Collection<CacheOperation> parseCacheAnnotations(Class<?> type);
/**
@@ -57,5 +59,6 @@ public interface CacheAnnotationParser {
* or {@code null} if none was found
* @see AnnotationCacheOperationSource#findCacheOperations(Method)
*/
@Nullable
Collection<CacheOperation> parseCacheAnnotations(Method method);
}

View File

@@ -20,6 +20,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.lang.Nullable;
/**
* Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
@@ -61,6 +62,7 @@ public interface CachingConfigurer {
* </pre>
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
CacheManager cacheManager();
/**
@@ -85,6 +87,7 @@ public interface CachingConfigurer {
* </pre>
* See {@link EnableCaching} for more complete examples.
*/
@Nullable
CacheResolver cacheResolver();
/**
@@ -105,6 +108,7 @@ public interface CachingConfigurer {
* </pre>
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
KeyGenerator keyGenerator();
/**
@@ -127,6 +131,7 @@ public interface CachingConfigurer {
* </pre>
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
CacheErrorHandler errorHandler();
}

View File

@@ -3,4 +3,7 @@
* Hooked into Spring's cache interception infrastructure via
* {@link org.springframework.cache.interceptor.CacheOperationSource}.
*/
@NonNullApi
package org.springframework.cache.annotation;
import org.springframework.lang.NonNullApi;

View File

@@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentMap;
import org.springframework.cache.support.AbstractValueAdaptingCache;
import org.springframework.core.serializer.support.SerializationDelegate;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -98,7 +99,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
* @since 4.3
*/
protected ConcurrentMapCache(String name, ConcurrentMap<Object, Object> store,
boolean allowNullValues, SerializationDelegate serialization) {
boolean allowNullValues, @Nullable SerializationDelegate serialization) {
super(allowNullValues);
Assert.notNull(name, "Name must not be null");

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.core.serializer.support.SerializationDelegate;
import org.springframework.lang.Nullable;
/**
* {@link CacheManager} implementation that lazily builds {@link ConcurrentMapCache}
@@ -81,7 +82,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
* <p>Calling this with a {@code null} collection argument resets the
* mode to 'dynamic', allowing for further creation of caches again.
*/
public void setCacheNames(Collection<String> cacheNames) {
public void setCacheNames(@Nullable Collection<String> cacheNames) {
if (cacheNames != null) {
for (String name : cacheNames) {
this.cacheMap.put(name, createConcurrentMapCache(name));

View File

@@ -4,4 +4,7 @@
* and {@link org.springframework.cache.Cache Cache} implementation for
* use in a Spring context, using a JDK based thread pool at runtime.
*/
@NonNullApi
package org.springframework.cache.concurrent;
import org.springframework.lang.NonNullApi;

View File

@@ -36,6 +36,7 @@ import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.cache.interceptor.CachePutOperation;
import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.cache.interceptor.NameMatchCacheOperationSource;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
@@ -241,6 +242,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
return builder;
}
@Nullable
String merge(Element element, ReaderContext readerCtx) {
String method = element.getAttribute(METHOD_ATTRIBUTE);
if (StringUtils.hasText(method)) {

View File

@@ -4,4 +4,7 @@
* org.springframework.cache.annotation.EnableCaching EnableCaching}
* for details on code-based configuration without XML.
*/
@NonNullApi
package org.springframework.cache.config;
import org.springframework.lang.NonNullApi;

View File

@@ -17,6 +17,7 @@
package org.springframework.cache.interceptor;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -66,6 +67,7 @@ public abstract class AbstractCacheInvoker {
* miss in case of error.
* @see Cache#get(Object)
*/
@Nullable
protected Cache.ValueWrapper doGet(Cache cache, Object key) {
try {
return cache.get(key);

View File

@@ -23,6 +23,7 @@ import java.util.Collections;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -93,6 +94,7 @@ public abstract class AbstractCacheResolver implements CacheResolver, Initializi
* @param context the context of the particular invocation
* @return the cache name(s) to resolve or {@code null} if no cache should be resolved
*/
@Nullable
protected abstract Collection<String> getCacheNames(CacheOperationInvocationContext<?> context);
}

View File

@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.MethodClassKey;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -116,10 +117,11 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
* @param targetClass the target class (may be {@code null})
* @return the cache key (never {@code null})
*/
protected Object getCacheKey(Method method, Class<?> targetClass) {
protected Object getCacheKey(Method method, @Nullable Class<?> targetClass) {
return new MethodClassKey(method, targetClass);
}
@Nullable
private Collection<CacheOperation> computeCacheOperations(Method method, Class<?> targetClass) {
// Don't allow no-public methods as required.
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
@@ -168,6 +170,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
* @return all caching attribute associated with this method
* (or {@code null} if none)
*/
@Nullable
protected abstract Collection<CacheOperation> findCacheOperations(Method method);
/**
@@ -177,6 +180,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
* @return all caching attribute associated with this class
* (or {@code null} if none)
*/
@Nullable
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz);
/**

View File

@@ -42,6 +42,7 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.expression.AnnotatedElementKey;
import org.springframework.expression.EvaluationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -470,6 +471,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
* @return a {@link Cache.ValueWrapper} holding the cached item,
* or {@code null} if none is found
*/
@Nullable
private Cache.ValueWrapper findCachedItem(Collection<CacheOperationContext> contexts) {
Object result = CacheOperationExpressionEvaluator.NO_RESULT;
for (CacheOperationContext context : contexts) {
@@ -507,6 +509,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
}
@Nullable
private Cache.ValueWrapper findInCaches(CacheOperationContext context, Object key) {
for (Cache cache : context.getCaches()) {
Cache.ValueWrapper wrapper = doGet(cache, key);
@@ -711,6 +714,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
* Compute the key for the given caching operation.
* @return the generated key, or {@code null} if none can be generated
*/
@Nullable
protected Object generateKey(Object result) {
if (StringUtils.hasText(this.metadata.operation.getKey())) {
EvaluationContext evaluationContext = createEvaluationContext(result);

View File

@@ -29,6 +29,7 @@ import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.context.expression.CachedExpressionEvaluator;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.lang.Nullable;
/**
* Utility class handling the SpEL expression parsing.
@@ -93,7 +94,7 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator {
* @return the evaluation context
*/
public EvaluationContext createEvaluationContext(Collection<? extends Cache> caches,
Method method, Object[] args, Object target, Class<?> targetClass, Object result,
Method method, Object[] args, Object target, Class<?> targetClass, @Nullable Object result,
BeanFactory beanFactory) {
CacheExpressionRootObject rootObject = new CacheExpressionRootObject(

View File

@@ -19,6 +19,8 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import java.util.Collection;
import org.springframework.lang.Nullable;
/**
* Interface used by {@link CacheInterceptor}. Implementations know how to source
* cache operation attributes, whether from configuration, metadata attributes at
@@ -37,6 +39,7 @@ public interface CacheOperationSource {
* the declaring class of the method must be used)
* @return all cache operations for this method, or {@code null} if none found
*/
Collection<CacheOperation> getCacheOperations(Method method, Class<?> targetClass);
@Nullable
Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass);
}

View File

@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.lang.reflect.Method;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
@@ -66,6 +67,7 @@ abstract class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut
* Obtain the underlying {@link CacheOperationSource} (may be {@code null}).
* To be implemented by subclasses.
*/
@Nullable
protected abstract CacheOperationSource getCacheOperationSource();
}

View File

@@ -3,4 +3,7 @@
* Builds on the AOP infrastructure in org.springframework.aop.framework.
* Any POJO can be cache-advised with Spring.
*/
@NonNullApi
package org.springframework.cache.interceptor;
import org.springframework.lang.NonNullApi;

View File

@@ -2,4 +2,7 @@
* Spring's generic cache abstraction.
* Concrete implementations are provided in the subpackages.
*/
@NonNullApi
package org.springframework.cache;
import org.springframework.lang.NonNullApi;

View File

@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentMap;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
/**
* Abstract base class implementing the common {@link CacheManager} methods.
@@ -124,6 +125,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
* @see #getCache(String)
* @see #getMissingCache(String)
*/
@Nullable
protected final Cache lookupCache(String name) {
return this.cacheMap.get(name);
}
@@ -183,6 +185,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
* @since 4.1
* @see #getCache(String)
*/
@Nullable
protected Cache getMissingCache(String name) {
return null;
}

View File

@@ -17,6 +17,7 @@
package org.springframework.cache.support;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
/**
* Common base class for {@link Cache} implementations that need to adapt
@@ -81,7 +82,8 @@ public abstract class AbstractValueAdaptingCache implements Cache {
* @param storeValue the store value
* @return the value to return to the user
*/
protected Object fromStoreValue(Object storeValue) {
@Nullable
protected Object fromStoreValue(@Nullable Object storeValue) {
if (this.allowNullValues && storeValue == NullValue.INSTANCE) {
return null;
}
@@ -94,7 +96,7 @@ public abstract class AbstractValueAdaptingCache implements Cache {
* @param userValue the given user value
* @return the value to store
*/
protected Object toStoreValue(Object userValue) {
protected Object toStoreValue(@Nullable Object userValue) {
if (userValue == null) {
if (this.allowNullValues) {
return NullValue.INSTANCE;

View File

@@ -17,6 +17,7 @@
package org.springframework.cache.support;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.lang.Nullable;
/**
* Straightforward implementation of {@link org.springframework.cache.Cache.ValueWrapper},
@@ -34,7 +35,7 @@ public class SimpleValueWrapper implements ValueWrapper {
* Create a new SimpleValueWrapper instance for exposing the given value.
* @param value the value to expose (may be {@code null})
*/
public SimpleValueWrapper(Object value) {
public SimpleValueWrapper(@Nullable Object value) {
this.value = value;
}

View File

@@ -2,4 +2,7 @@
* Support classes for the org.springframework.cache package.
* Provides abstract classes for cache managers and caches.
*/
@NonNullApi
package org.springframework.cache.support;
import org.springframework.lang.NonNullApi;

View File

@@ -21,6 +21,7 @@ import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.lang.Nullable;
/**
* Central interface to provide configuration for an application.
@@ -61,6 +62,7 @@ public interface ApplicationContext extends EnvironmentCapable, ListableBeanFact
* Return the unique id of this application context.
* @return the unique id of the context, or {@code null} if none
*/
@Nullable
String getId();
/**
@@ -86,6 +88,7 @@ public interface ApplicationContext extends EnvironmentCapable, ListableBeanFact
* and this is the root of the context hierarchy.
* @return the parent context, or {@code null} if there is no parent
*/
@Nullable
ApplicationContext getParent();
/**

View File

@@ -24,6 +24,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ProtocolResolver;
import org.springframework.lang.Nullable;
/**
* SPI interface to be implemented by most if not all application contexts.
@@ -100,7 +101,7 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
* @param parent the parent context
* @see org.springframework.web.context.ConfigurableWebApplicationContext
*/
void setParent(ApplicationContext parent);
void setParent(@Nullable ApplicationContext parent);
/**
* Set the {@code Environment} for this application context.

View File

@@ -16,6 +16,8 @@
package org.springframework.context;
import org.springframework.lang.Nullable;
/**
* Sub-interface of MessageSource to be implemented by objects that
* can resolve messages hierarchically.
@@ -32,11 +34,12 @@ public interface HierarchicalMessageSource extends MessageSource {
* resolve messages that this object can't resolve.
* May be {@code null}, in which case no further resolution is possible.
*/
void setParentMessageSource(MessageSource parent);
void setParentMessageSource(@Nullable MessageSource parent);
/**
* Return the parent of this MessageSource, or {@code null} if none.
*/
@Nullable
MessageSource getParentMessageSource();
}

View File

@@ -18,6 +18,8 @@ package org.springframework.context;
import java.util.Locale;
import org.springframework.lang.Nullable;
/**
* Strategy interface for resolving messages, with support for the parameterization
* and internationalization of such messages.
@@ -51,7 +53,7 @@ public interface MessageSource {
* otherwise the default message passed as a parameter
* @see java.text.MessageFormat
*/
String getMessage(String code, Object[] args, String defaultMessage, Locale locale);
String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale);
/**
* Try to resolve the message. Treat as an error if the message can't be found.
@@ -64,7 +66,7 @@ public interface MessageSource {
* @throws NoSuchMessageException if the message wasn't found
* @see java.text.MessageFormat
*/
String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException;
String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException;
/**
* Try to resolve the message using all the attributes contained within the

View File

@@ -16,6 +16,8 @@
package org.springframework.context;
import org.springframework.lang.Nullable;
/**
* Interface for objects that are suitable for message resolution in a
* {@link MessageSource}.
@@ -44,6 +46,7 @@ public interface MessageSourceResolvable {
* placeholders within the message text
* @see java.text.MessageFormat
*/
@Nullable
default Object[] getArguments() {
return null;
}
@@ -57,6 +60,7 @@ public interface MessageSourceResolvable {
* for this particular message.
* @return the default message, or {@code null} if no default
*/
@Nullable
default String getDefaultMessage() {
return null;
}

View File

@@ -21,8 +21,9 @@ import java.lang.annotation.Annotation;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
/**
/**
* Convenient base class for {@link ImportSelector} implementations that select imports
* based on an {@link AdviceMode} value from an annotation (such as the {@code @Enable*}
* annotations).
@@ -85,6 +86,7 @@ public abstract class AdviceModeImportSelector<A extends Annotation> implements
* @return array containing classes to import; empty array if none, {@code null} if
* the given {@code AdviceMode} is unknown.
*/
@Nullable
protected abstract String[] selectImports(AdviceMode adviceMode);
}

View File

@@ -30,6 +30,7 @@ import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.core.env.Environment;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -153,7 +154,7 @@ public class AnnotatedBeanDefinitionReader {
* (may be {@code null})
* @since 5.0
*/
public <T> void registerBean(Class<T> annotatedClass, Supplier<T> instanceSupplier) {
public <T> void registerBean(Class<T> annotatedClass, @Nullable Supplier<T> instanceSupplier) {
doRegisterBean(annotatedClass, instanceSupplier, null, null);
}
@@ -167,7 +168,7 @@ public class AnnotatedBeanDefinitionReader {
* (may be {@code null})
* @since 5.0
*/
public <T> void registerBean(Class<T> annotatedClass, String name, Supplier<T> instanceSupplier) {
public <T> void registerBean(Class<T> annotatedClass, String name, @Nullable Supplier<T> instanceSupplier) {
doRegisterBean(annotatedClass, instanceSupplier, name, null);
}
@@ -209,8 +210,8 @@ 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, Supplier<T> instanceSupplier, String name,
Class<? extends Annotation>[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) {
<T> void doRegisterBean(Class<T> annotatedClass, @Nullable Supplier<T> instanceSupplier, String name,
@Nullable Class<? extends Annotation>[] qualifiers, BeanDefinitionCustomizer... definitionCustomizers) {
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);
if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {

View File

@@ -26,6 +26,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -82,6 +83,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
* @param annotatedDef the annotation-aware bean definition
* @return the bean name, or {@code null} if none is found
*/
@Nullable
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
AnnotationMetadata amd = annotatedDef.getMetadata();
Set<String> types = amd.getAnnotationTypes();
@@ -131,6 +133,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
* @param registry the registry that the given bean definition is being registered with
* @return the default bean name (never {@code null})
*/
@Nullable
protected String buildDefaultBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return buildDefaultBeanName(definition);
}
@@ -145,6 +148,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
* @param definition the bean definition to build a bean name for
* @return the default bean name (never {@code null})
*/
@Nullable
protected String buildDefaultBeanName(BeanDefinition definition) {
String shortClassName = ClassUtils.getShortName(definition.getBeanClassName());
return Introspector.decapitalize(shortClassName);

View File

@@ -23,6 +23,7 @@ import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -187,7 +188,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
* (may be {@code null} or empty)
* @since 5.0
*/
public <T> void registerBean(Class<T> annotatedClass, Object... constructorArguments) {
public <T> void registerBean(Class<T> annotatedClass, @Nullable Object... constructorArguments) {
registerBean(null, annotatedClass, constructorArguments);
}
@@ -203,7 +204,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
* (may be {@code null} or empty)
* @since 5.0
*/
public <T> void registerBean(String beanName, Class<T> annotatedClass, Object... constructorArguments) {
public <T> void registerBean(@Nullable String beanName, Class<T> annotatedClass, @Nullable Object... constructorArguments) {
this.reader.doRegisterBean(annotatedClass, null, beanName, null,
bd -> {
for (Object arg : constructorArguments) {

View File

@@ -37,6 +37,7 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -143,7 +144,7 @@ public class AnnotationConfigUtils {
* that have actually been registered by this call
*/
public static Set<BeanDefinitionHolder> registerAnnotationConfigProcessors(
BeanDefinitionRegistry registry, Object source) {
BeanDefinitionRegistry registry, @Nullable Object source) {
DefaultListableBeanFactory beanFactory = unwrapDefaultListableBeanFactory(registry);
if (beanFactory != null) {
@@ -219,6 +220,7 @@ public class AnnotationConfigUtils {
return new BeanDefinitionHolder(definition, beanName);
}
@Nullable
private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) {
if (registry instanceof DefaultListableBeanFactory) {
return (DefaultListableBeanFactory) registry;

View File

@@ -51,6 +51,7 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Indexed;
@@ -237,6 +238,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
/**
* Return the {@link BeanDefinitionRegistry} used by this scanner, if any.
*/
@Nullable
protected BeanDefinitionRegistry getRegistry() {
return null;
}
@@ -341,6 +343,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
* @since 5.0
* @see #isIndexSupportsIncludeFilter(TypeFilter)
*/
@Nullable
protected String extractStereotype(TypeFilter filter) {
if (filter instanceof AnnotationTypeFilter) {
return ((AnnotationTypeFilter) filter).getAnnotationType().getName();

View File

@@ -20,6 +20,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
/**
* Context information for use by {@link Condition}s.
@@ -34,6 +35,7 @@ public interface ConditionContext {
* should the condition match or {@code null} if the registry is not available.
* @return the registry or {@code null}
*/
@Nullable
BeanDefinitionRegistry getRegistry();
/**
@@ -42,6 +44,7 @@ public interface ConditionContext {
* is not available.
* @return the bean factory or {@code null}
*/
@Nullable
ConfigurableListableBeanFactory getBeanFactory();
/**
@@ -49,6 +52,7 @@ public interface ConditionContext {
* or {@code null} if no environment is available.
* @return the environment or {@code null}
*/
@Nullable
Environment getEnvironment();
/**
@@ -56,6 +60,7 @@ public interface ConditionContext {
* if the resource loader cannot be obtained.
* @return a resource loader or {@code null}
*/
@Nullable
ResourceLoader getResourceLoader();
/**
@@ -63,6 +68,7 @@ public interface ConditionContext {
* classes or {@code null} if the default classloader should be used.
* @return the class loader or {@code null}
*/
@Nullable
ClassLoader getClassLoader();
}

View File

@@ -31,6 +31,7 @@ import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.MultiValueMap;
@@ -141,6 +142,7 @@ class ConditionEvaluator {
this.resourceLoader = (resourceLoader != null ? resourceLoader : deduceResourceLoader(registry));
}
@Nullable
private ConfigurableListableBeanFactory deduceBeanFactory(BeanDefinitionRegistry source) {
if (source instanceof ConfigurableListableBeanFactory) {
return (ConfigurableListableBeanFactory) source;
@@ -151,6 +153,7 @@ class ConditionEvaluator {
return null;
}
@Nullable
private Environment deduceEnvironment(BeanDefinitionRegistry source) {
if (source instanceof EnvironmentCapable) {
return ((EnvironmentCapable) source).getEnvironment();
@@ -158,6 +161,7 @@ class ConditionEvaluator {
return null;
}
@Nullable
private ResourceLoader deduceResourceLoader(BeanDefinitionRegistry source) {
if (source instanceof ResourceLoader) {
return (ResourceLoader) source;

View File

@@ -31,6 +31,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -88,7 +89,7 @@ final class ConfigurationClass {
* @param importedBy the configuration class importing this one or {@code null}
* @since 3.1.1
*/
public ConfigurationClass(MetadataReader metadataReader, ConfigurationClass importedBy) {
public ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) {
this.metadata = metadataReader.getAnnotationMetadata();
this.resource = metadataReader.getResource();
this.importedBy.add(importedBy);
@@ -115,7 +116,7 @@ final class ConfigurationClass {
* @param importedBy the configuration class importing this one or {@code null}
* @since 3.1.1
*/
public ConfigurationClass(Class<?> clazz, ConfigurationClass importedBy) {
public ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) {
this.metadata = new StandardAnnotationMetadata(clazz, true);
this.resource = new DescriptiveResource(clazz.getName());
this.importedBy.add(importedBy);

View File

@@ -49,6 +49,7 @@ import org.springframework.cglib.proxy.NoOp;
import org.springframework.cglib.transform.ClassEmitterTransformer;
import org.springframework.cglib.transform.TransformingClassGenerator;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
import org.springframework.objenesis.ObjenesisException;
import org.springframework.objenesis.SpringObjenesis;
import org.springframework.util.Assert;
@@ -269,6 +270,7 @@ class ConfigurationClassEnhancer {
private static class BeanFactoryAwareMethodInterceptor implements MethodInterceptor, ConditionalCallback {
@Override
@Nullable
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
Field field = ReflectionUtils.findField(obj.getClass(), BEAN_FACTORY_FIELD);
Assert.state(field != null, "Unable to find generated BeanFactory field");

View File

@@ -72,6 +72,7 @@ import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
@@ -258,6 +259,7 @@ class ConfigurationClassParser {
* @param sourceClass a source class
* @return the superclass, or {@code null} if none found or previously processed
*/
@Nullable
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass)
throws IOException {

View File

@@ -32,6 +32,7 @@ import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean;
import org.springframework.jndi.JndiLocatorDelegate;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -152,6 +153,7 @@ public class MBeanExportConfiguration implements ImportAware, EnvironmentAware,
public abstract MBeanServer getMBeanServer();
@Nullable
public static SpecificPlatform get() {
ClassLoader classLoader = MBeanExportConfiguration.class.getClassLoader();
for (SpecificPlatform environment : values()) {

View File

@@ -3,4 +3,7 @@
* annotations, component-scanning, and Java-based metadata for creating
* Spring-managed objects.
*/
@NonNullApi
package org.springframework.context.annotation;
import org.springframework.lang.NonNullApi;

View File

@@ -26,6 +26,7 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.jmx.support.MBeanServerFactoryBean;
import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean;
import org.springframework.jndi.JndiObjectFactoryBean;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -82,6 +83,7 @@ class MBeanServerBeanDefinitionParser extends AbstractBeanDefinitionParser {
return bd;
}
@Nullable
static AbstractBeanDefinition findServerForSpecialEnvironment() {
if (weblogicPresent) {
RootBeanDefinition bd = new RootBeanDefinition(JndiObjectFactoryBean.class);

View File

@@ -2,4 +2,7 @@
* Support package for advanced application context configuration,
* with XML schema being the primary configuration format.
*/
@NonNullApi
package org.springframework.context.config;
import org.springframework.lang.NonNullApi;

View File

@@ -19,6 +19,7 @@ package org.springframework.context.event;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
/**
* Interface to be implemented by objects that can manage a number of
@@ -81,6 +82,6 @@ public interface ApplicationEventMulticaster {
* @param eventType the type of event (can be null)
* @since 4.2
*/
void multicastEvent(ApplicationEvent event, ResolvableType eventType);
void multicastEvent(ApplicationEvent event, @Nullable ResolvableType eventType);
}

View File

@@ -36,6 +36,7 @@ import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.Order;
import org.springframework.expression.EvaluationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -187,6 +188,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
* return {@code null} to indicate that no suitable arguments could be resolved and
* therefore the method should not be invoked at all for the specified event.
*/
@Nullable
protected Object[] resolveArguments(ApplicationEvent event) {
ResolvableType declaredEventType = getResolvableType(event);
if (declaredEventType == null) {
@@ -338,7 +340,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
return sb.toString();
}
@Nullable
private ResolvableType getResolvableType(ApplicationEvent event) {
ResolvableType payloadType = null;
if (event instanceof PayloadApplicationEvent) {

View File

@@ -21,6 +21,7 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -88,7 +89,7 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList
return (this.delegate instanceof Ordered ? ((Ordered) this.delegate).getOrder() : Ordered.LOWEST_PRECEDENCE);
}
@Nullable
static ResolvableType resolveDeclaredEventType(Class<?> listenerType) {
ResolvableType resolvableType = ResolvableType.forClass(listenerType).as(ApplicationListener.class);
if (resolvableType == null || !resolvableType.hasGenerics()) {

View File

@@ -2,4 +2,7 @@
* Support classes for application events, like standard context events.
* To be supported by all major application context implementations.
*/
@NonNullApi
package org.springframework.context.event;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Expression parsing support within a Spring application context.
*/
@NonNullApi
package org.springframework.context.expression;
import org.springframework.lang.NonNullApi;

View File

@@ -18,6 +18,8 @@ package org.springframework.context.i18n;
import java.util.Locale;
import org.springframework.lang.Nullable;
/**
* Strategy interface for determining the current Locale.
*
@@ -36,6 +38,7 @@ public interface LocaleContext {
* depending on the implementation strategy.
* @return the current Locale, or {@code null} if no specific Locale associated
*/
@Nullable
Locale getLocale();
}

View File

@@ -21,6 +21,7 @@ import java.util.TimeZone;
import org.springframework.core.NamedInheritableThreadLocal;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
/**
* Simple holder class that associates a LocaleContext instance
@@ -74,7 +75,7 @@ public abstract class LocaleContextHolder {
* @see SimpleLocaleContext
* @see SimpleTimeZoneAwareLocaleContext
*/
public static void setLocaleContext(LocaleContext localeContext) {
public static void setLocaleContext(@Nullable LocaleContext localeContext) {
setLocaleContext(localeContext, false);
}
@@ -89,7 +90,7 @@ public abstract class LocaleContextHolder {
* @see SimpleLocaleContext
* @see SimpleTimeZoneAwareLocaleContext
*/
public static void setLocaleContext(LocaleContext localeContext, boolean inheritable) {
public static void setLocaleContext(@Nullable LocaleContext localeContext, boolean inheritable) {
if (localeContext == null) {
resetLocaleContext();
}
@@ -109,6 +110,7 @@ public abstract class LocaleContextHolder {
* Return the LocaleContext associated with the current thread, if any.
* @return the current LocaleContext, or {@code null} if none
*/
@Nullable
public static LocaleContext getLocaleContext() {
LocaleContext localeContext = localeContextHolder.get();
if (localeContext == null) {
@@ -127,7 +129,7 @@ public abstract class LocaleContextHolder {
* @see #setTimeZone(TimeZone)
* @see SimpleLocaleContext#SimpleLocaleContext(Locale)
*/
public static void setLocale(Locale locale) {
public static void setLocale(@Nullable Locale locale) {
setLocale(locale, false);
}
@@ -142,7 +144,7 @@ public abstract class LocaleContextHolder {
* @see #setTimeZone(TimeZone, boolean)
* @see SimpleLocaleContext#SimpleLocaleContext(Locale)
*/
public static void setLocale(Locale locale, boolean inheritable) {
public static void setLocale(@Nullable Locale locale, boolean inheritable) {
LocaleContext localeContext = getLocaleContext();
TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ?
((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null);
@@ -172,7 +174,7 @@ public abstract class LocaleContextHolder {
* @see #getLocale()
* @see Locale#getDefault()
*/
public static void setDefaultLocale(Locale locale) {
public static void setDefaultLocale(@Nullable Locale locale) {
LocaleContextHolder.defaultLocale = locale;
}
@@ -213,7 +215,7 @@ public abstract class LocaleContextHolder {
* @see #setLocale(Locale)
* @see SimpleTimeZoneAwareLocaleContext#SimpleTimeZoneAwareLocaleContext(Locale, TimeZone)
*/
public static void setTimeZone(TimeZone timeZone) {
public static void setTimeZone(@Nullable TimeZone timeZone) {
setTimeZone(timeZone, false);
}
@@ -228,7 +230,7 @@ public abstract class LocaleContextHolder {
* @see #setLocale(Locale, boolean)
* @see SimpleTimeZoneAwareLocaleContext#SimpleTimeZoneAwareLocaleContext(Locale, TimeZone)
*/
public static void setTimeZone(TimeZone timeZone, boolean inheritable) {
public static void setTimeZone(@Nullable TimeZone timeZone, boolean inheritable) {
LocaleContext localeContext = getLocaleContext();
Locale locale = (localeContext != null ? localeContext.getLocale() : null);
if (timeZone != null) {
@@ -257,7 +259,7 @@ public abstract class LocaleContextHolder {
* @see #getTimeZone()
* @see TimeZone#getDefault()
*/
public static void setDefaultTimeZone(TimeZone timeZone) {
public static void setDefaultTimeZone(@Nullable TimeZone timeZone) {
defaultTimeZone = timeZone;
}

View File

@@ -18,6 +18,8 @@ package org.springframework.context.i18n;
import java.util.TimeZone;
import org.springframework.lang.Nullable;
/**
* Extension of {@link LocaleContext}, adding awareness of the current time zone.
*
@@ -37,6 +39,7 @@ public interface TimeZoneAwareLocaleContext extends LocaleContext {
* depending on the implementation strategy.
* @return the current TimeZone, or {@code null} if no specific TimeZone associated
*/
@Nullable
TimeZone getTimeZone();
}

View File

@@ -2,4 +2,7 @@
* Abstraction for determining the current Locale,
* plus global holder that exposes a thread-bound Locale.
*/
@NonNullApi
package org.springframework.context.i18n;
import org.springframework.lang.NonNullApi;

View File

@@ -30,6 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.core.SpringProperties;
import org.springframework.core.io.UrlResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ConcurrentReferenceHashMap;
/**
@@ -75,7 +76,8 @@ public class CandidateComponentsIndexLoader {
* @throws IllegalArgumentException if any module index cannot
* be loaded or if an error occurs while creating {@link CandidateComponentsIndex}
*/
public static CandidateComponentsIndex loadIndex(ClassLoader classLoader) {
@Nullable
public static CandidateComponentsIndex loadIndex(@Nullable ClassLoader classLoader) {
ClassLoader classLoaderToUse = classLoader;
if (classLoaderToUse == null) {
classLoaderToUse = CandidateComponentsIndexLoader.class.getClassLoader();
@@ -83,6 +85,7 @@ public class CandidateComponentsIndexLoader {
return cache.computeIfAbsent(classLoaderToUse, CandidateComponentsIndexLoader::doLoadIndex);
}
@Nullable
private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) {
if (shouldIgnoreIndex) {
return null;

View File

@@ -1,4 +1,7 @@
/**
* Support package for reading and managing the components index.
*/
@NonNullApi
package org.springframework.context.index;
import org.springframework.lang.NonNullApi;

View File

@@ -10,4 +10,7 @@
* is that application objects can often be configured without
* any dependency on Spring-specific APIs.
*/
@NonNullApi
package org.springframework.context;
import org.springframework.lang.NonNullApi;

View File

@@ -26,6 +26,7 @@ import org.springframework.context.HierarchicalMessageSource;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -93,6 +94,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
/**
* Return a Properties object defining locale-independent common messages, if any.
*/
@Nullable
protected Properties getCommonMessages() {
return this.commonMessages;
}
@@ -192,6 +194,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
* @see #getMessage(MessageSourceResolvable, Locale)
* @see #setUseCodeAsDefaultMessage
*/
@Nullable
protected String getMessageInternal(String code, Object[] args, Locale locale) {
if (code == null) {
return null;
@@ -248,6 +251,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
* @return the resolved message, or {@code null} if not found
* @see #getParentMessageSource()
*/
@Nullable
protected String getMessageFromParent(String code, Object[] args, Locale locale) {
MessageSource parent = getParentMessageSource();
if (parent != null) {
@@ -277,6 +281,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
* @see #renderDefaultMessage(String, Object[], Locale)
* @see #getDefaultMessage(String)
*/
@Nullable
protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) {
String defaultMessage = resolvable.getDefaultMessage();
String[] codes = resolvable.getCodes();
@@ -300,6 +305,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
* @return the default message to use, or {@code null} if none
* @see #setUseCodeAsDefaultMessage
*/
@Nullable
protected String getDefaultMessage(String code) {
if (isUseCodeAsDefaultMessage()) {
return code;
@@ -350,6 +356,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
* @see #resolveCode
* @see java.text.MessageFormat
*/
@Nullable
protected String resolveCodeWithoutArguments(String code, Locale locale) {
MessageFormat messageFormat = resolveCode(code, locale);
if (messageFormat != null) {
@@ -373,6 +380,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme
* @return the MessageFormat for the message, or {@code null} if not found
* @see #resolveCodeWithoutArguments(String, java.util.Locale)
*/
@Nullable
protected abstract MessageFormat resolveCode(String code, Locale locale);
}

View File

@@ -19,6 +19,7 @@ package org.springframework.context.support;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -94,6 +95,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra
* @see #getResources
* @see #getResourcePatternResolver
*/
@Nullable
protected String[] getConfigLocations() {
return (this.configLocations != null ? this.configLocations : getDefaultConfigLocations());
}
@@ -106,6 +108,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra
* @return an array of default config locations, if any
* @see #setConfigLocations
*/
@Nullable
protected String[] getDefaultConfigLocations() {
return null;
}

View File

@@ -19,6 +19,7 @@ package org.springframework.context.support;
import java.util.LinkedHashSet;
import java.util.Set;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -126,6 +127,7 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage
* Return the default charset to use for parsing properties files, if any.
* @since 4.3
*/
@Nullable
protected String getDefaultEncoding() {
return this.defaultEncoding;
}

View File

@@ -24,6 +24,7 @@ import org.springframework.beans.factory.xml.ResourceEntityResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
/**
* Convenient base class for {@link org.springframework.context.ApplicationContext}
@@ -136,6 +137,7 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC
* @return an array of Resource objects, or {@code null} if none
* @see #getConfigLocations()
*/
@Nullable
protected Resource[] getConfigResources() {
return null;
}

View File

@@ -34,6 +34,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -384,7 +385,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
* @since 5.0
* @see #registerBean(String, Class, Supplier, BeanDefinitionCustomizer...)
*/
public final <T> void registerBean(String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) {
public final <T> void registerBean(@Nullable String beanName, Class<T> beanClass, BeanDefinitionCustomizer... customizers) {
registerBean(beanName, beanClass, null, customizers);
}
@@ -418,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(String beanName, Class<T> beanClass, Supplier<T> supplier,
public <T> void registerBean(@Nullable String beanName, @Nullable Class<T> beanClass, Supplier<T> supplier,
BeanDefinitionCustomizer... customizers) {
Assert.isTrue(beanName != null || beanClass != null, "Either bean name or bean class must be specified");

View File

@@ -31,6 +31,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -223,6 +224,7 @@ public class LiveBeansView implements LiveBeansViewMBean, ApplicationContextAwar
* @param bd the bean definition to build the resource description for
* @return the JSON-escaped resource description
*/
@Nullable
protected String getEscapedResourceDescription(BeanDefinition bd) {
String resourceDescription = bd.getResourceDescription();
if (resourceDescription == null) {

View File

@@ -22,6 +22,7 @@ import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.lang.Nullable;
/**
* Helper class for easy access to messages from a MessageSource,
@@ -101,7 +102,7 @@ public class MessageSourceAccessor {
* @param defaultMessage String to return if the lookup fails
* @return the message
*/
public String getMessage(String code, Object[] args, String defaultMessage) {
public String getMessage(String code, @Nullable Object[] args, String defaultMessage) {
return this.messageSource.getMessage(code, args, defaultMessage, getDefaultLocale());
}
@@ -113,7 +114,7 @@ public class MessageSourceAccessor {
* @param locale Locale in which to do lookup
* @return the message
*/
public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
public String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale) {
return this.messageSource.getMessage(code, args, defaultMessage, locale);
}
@@ -145,7 +146,7 @@ public class MessageSourceAccessor {
* @return the message
* @throws org.springframework.context.NoSuchMessageException if not found
*/
public String getMessage(String code, Object[] args) throws NoSuchMessageException {
public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException {
return this.messageSource.getMessage(code, args, getDefaultLocale());
}
@@ -157,7 +158,7 @@ public class MessageSourceAccessor {
* @return the message
* @throws org.springframework.context.NoSuchMessageException if not found
*/
public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException {
return this.messageSource.getMessage(code, args, locale);
}

View File

@@ -22,6 +22,7 @@ import java.util.ResourceBundle;
import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -70,6 +71,7 @@ public class MessageSourceResourceBundle extends ResourceBundle {
* Returns {@code null} if the message could not be resolved.
*/
@Override
@Nullable
protected Object handleGetObject(String key) {
try {
return this.messageSource.getMessage(key, null, this.locale);

View File

@@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -96,7 +97,7 @@ public abstract class MessageSourceSupport {
* @return the rendered default message (with resolved arguments)
* @see #formatMessage(String, Object[], java.util.Locale)
*/
protected String renderDefaultMessage(String defaultMessage, Object[] args, Locale locale) {
protected String renderDefaultMessage(String defaultMessage, @Nullable Object[] args, Locale locale) {
return formatMessage(defaultMessage, args, locale);
}

View File

@@ -33,6 +33,7 @@ import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.DefaultPropertiesPersister;
import org.springframework.util.PropertiesPersister;
import org.springframework.util.StringUtils;
@@ -395,7 +396,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
* @param filename the bundle filename (basename + Locale)
* @param propHolder the current PropertiesHolder for the bundle
*/
protected PropertiesHolder refreshProperties(String filename, PropertiesHolder propHolder) {
protected PropertiesHolder refreshProperties(String filename, @Nullable PropertiesHolder propHolder) {
long refreshTimestamp = (getCacheMillis() < 0 ? -1 : System.currentTimeMillis());
Resource resource = this.resourceLoader.getResource(filename + PROPERTIES_SUFFIX);
@@ -585,6 +586,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
return this.refreshTimestamp;
}
@Nullable
public String getProperty(String code) {
if (this.properties == null) {
return null;
@@ -592,6 +594,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased
return this.properties.getProperty(code);
}
@Nullable
public MessageFormat getMessageFormat(String code, Locale locale) {
if (this.properties == null) {
return null;

View File

@@ -35,6 +35,7 @@ import java.util.ResourceBundle;
import java.util.Set;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -165,6 +166,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
* @return the resulting ResourceBundle, or {@code null} if none
* found for the given basename and Locale
*/
@Nullable
protected ResourceBundle getResourceBundle(String basename, Locale locale) {
if (getCacheMillis() >= 0) {
// Fresh ResourceBundle.getBundle call in order to let ResourceBundle
@@ -238,6 +240,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
* defined for the given code
* @throws MissingResourceException if thrown by the ResourceBundle
*/
@Nullable
protected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Locale locale)
throws MissingResourceException {
@@ -287,6 +290,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou
* @see ResourceBundle#getString(String)
* @see ResourceBundle#containsKey(String)
*/
@Nullable
protected String getStringOrNull(ResourceBundle bundle, String key) {
if (bundle.containsKey(key)) {
try {

View File

@@ -3,4 +3,7 @@
* such as abstract base classes for ApplicationContext
* implementations and a MessageSource implementation.
*/
@NonNullApi
package org.springframework.context.support;
import org.springframework.lang.NonNullApi;

View File

@@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.lang.Nullable;
/**
* Post-processor that registers AspectJ's
@@ -77,7 +78,7 @@ public class AspectJWeavingEnabler
* @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver)
* @param beanClassLoader the class loader to create a default weaver for (if necessary)
*/
public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) {
public static void enableAspectJWeaving(@Nullable LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) {
if (weaverToUse == null) {
if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
weaverToUse = new InstrumentationLoadTimeWeaver(beanClassLoader);

View File

@@ -32,6 +32,7 @@ import org.springframework.instrument.classloading.jboss.JBossLoadTimeWeaver;
import org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver;
import org.springframework.instrument.classloading.weblogic.WebLogicLoadTimeWeaver;
import org.springframework.instrument.classloading.websphere.WebSphereLoadTimeWeaver;
import org.springframework.lang.Nullable;
/**
* Default {@link LoadTimeWeaver} bean for use in an application context,
@@ -105,6 +106,7 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo
* of a specific method (addInstanceClassPreProcessor) for any earlier
* versions even though the ClassLoader name is the same.
*/
@Nullable
protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) {
String name = classLoader.getClass().getName();
try {

View File

@@ -22,6 +22,7 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -65,7 +66,7 @@ public class LoadTimeWeaverAwareProcessor implements BeanPostProcessor, BeanFact
* {@link ConfigurableApplicationContext#LOAD_TIME_WEAVER_BEAN_NAME "loadTimeWeaver"}.
* @param loadTimeWeaver the specific {@code LoadTimeWeaver} that is to be used
*/
public LoadTimeWeaverAwareProcessor(LoadTimeWeaver loadTimeWeaver) {
public LoadTimeWeaverAwareProcessor(@Nullable LoadTimeWeaver loadTimeWeaver) {
this.loadTimeWeaver = loadTimeWeaver;
}

View File

@@ -2,4 +2,7 @@
* Load-time weaving support for a Spring application context, building on Spring's
* {@link org.springframework.instrument.classloading.LoadTimeWeaver} abstraction.
*/
@NonNullApi
package org.springframework.context.weaving;
import org.springframework.lang.NonNullApi;

View File

@@ -25,6 +25,7 @@ import javax.naming.NamingException;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.lang.Nullable;
import org.springframework.remoting.RemoteConnectFailureException;
import org.springframework.remoting.RemoteLookupFailureException;
import org.springframework.remoting.rmi.RmiClientInterceptorUtils;
@@ -164,6 +165,7 @@ public abstract class AbstractRemoteSlsbInvokerInterceptor extends AbstractSlsbI
* @throws Throwable in case of invocation failure
* @see #invoke
*/
@Nullable
protected Object refreshAndRetry(MethodInvocation invocation) throws Throwable {
try {
refreshHome();
@@ -184,6 +186,7 @@ public abstract class AbstractRemoteSlsbInvokerInterceptor extends AbstractSlsbI
* @see #getHome
* @see #newSessionBeanInstance
*/
@Nullable
protected abstract Object doInvoke(MethodInvocation invocation) throws Throwable;

View File

@@ -25,6 +25,7 @@ import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.jndi.JndiObjectLocator;
import org.springframework.lang.Nullable;
/**
* Base class for AOP interceptors invoking local or remote Stateless Session Beans.
@@ -132,6 +133,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator
* @return the create method
* @throws EjbAccessException if the method couldn't be retrieved
*/
@Nullable
protected Method getCreateMethod(Object home) throws EjbAccessException {
try {
// Cache the EJB create() method that must be declared on the home interface.
@@ -201,6 +203,7 @@ public abstract class AbstractSlsbInvokerInterceptor extends JndiObjectLocator
* @return the invocation result, if any
* @throws Throwable in case of invocation failure
*/
@Nullable
protected abstract Object invokeInContext(MethodInvocation invocation) throws Throwable;

View File

@@ -19,4 +19,7 @@
* It now uses FactoryBeans and AOP, rather than the custom bean definitions described in
* <i>Expert One-on-One J2EE</i>.
*/
@NonNullApi
package org.springframework.ejb.access;
import org.springframework.lang.NonNullApi;

View File

@@ -2,4 +2,7 @@
* Support package for EJB/Java EE-related configuration,
* with XML schema being the primary configuration format.
*/
@NonNullApi
package org.springframework.ejb.config;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Annotations for declaratively configuring field formatting rules.
*/
@NonNullApi
package org.springframework.format.annotation;
import org.springframework.lang.NonNullApi;

View File

@@ -24,6 +24,7 @@ import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -129,7 +130,7 @@ public class DateTimeFormatterFactory {
* factory properties have been set (can be {@code null}).
* @return a new date time formatter
*/
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
public DateTimeFormatter createDateTimeFormatter(@Nullable DateTimeFormatter fallbackFormatter) {
DateTimeFormatter dateTimeFormatter = null;
if (StringUtils.hasLength(this.pattern)) {
dateTimeFormatter = DateTimeFormat.forPattern(this.pattern);

View File

@@ -25,6 +25,7 @@ import org.joda.time.format.DateTimeFormatter;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
import org.springframework.lang.Nullable;
/**
* A context that holds user-specific Joda-Time settings such as the user's
@@ -53,6 +54,7 @@ public class JodaTimeContext {
/**
* Return the user's chronology (calendar system), if any.
*/
@Nullable
public Chronology getChronology() {
return this.chronology;
}
@@ -72,6 +74,7 @@ public class JodaTimeContext {
/**
* Return the user's time zone, if any.
*/
@Nullable
public DateTimeZone getTimeZone() {
return this.timeZone;
}

View File

@@ -21,6 +21,7 @@ import java.util.Locale;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
/**
* A holder for a thread-local {@link JodaTimeContext}
@@ -49,7 +50,7 @@ public final class JodaTimeContextHolder {
* @param jodaTimeContext the current JodaTimeContext,
* or {@code null} to reset the thread-bound context
*/
public static void setJodaTimeContext(JodaTimeContext jodaTimeContext) {
public static void setJodaTimeContext(@Nullable JodaTimeContext jodaTimeContext) {
if (jodaTimeContext == null) {
resetJodaTimeContext();
}
@@ -62,6 +63,7 @@ public final class JodaTimeContextHolder {
* Return the JodaTimeContext associated with the current thread, if any.
* @return the current JodaTimeContext, or {@code null} if none
*/
@Nullable
public static JodaTimeContext getJodaTimeContext() {
return jodaTimeContextHolder.get();
}
@@ -74,7 +76,7 @@ public final class JodaTimeContextHolder {
* @param locale the current user locale (may be {@code null} if not known)
* @return the user-specific DateTimeFormatter
*/
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) {
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) {
DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
JodaTimeContext context = getJodaTimeContext();
return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);

View File

@@ -1,4 +1,7 @@
/**
* Integration with Joda-Time for formatting Joda date and time types as well as standard JDK Date types.
*/
@NonNullApi
package org.springframework.format.datetime.joda;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Formatters for {@code java.util.Date} properties.
*/
@NonNullApi
package org.springframework.format.datetime;
import org.springframework.lang.NonNullApi;

View File

@@ -24,6 +24,7 @@ import java.util.TimeZone;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
import org.springframework.lang.Nullable;
/**
* A context that holds user-specific <code>java.time</code> (JSR-310) settings
@@ -51,6 +52,7 @@ public class DateTimeContext {
/**
* Return the user's chronology (calendar system), if any.
*/
@Nullable
public Chronology getChronology() {
return this.chronology;
}
@@ -70,6 +72,7 @@ public class DateTimeContext {
/**
* Return the user's time zone, if any.
*/
@Nullable
public ZoneId getTimeZone() {
return this.timeZone;
}

View File

@@ -20,6 +20,7 @@ import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
/**
* A holder for a thread-local user {@link DateTimeContext}.
@@ -46,7 +47,7 @@ public final class DateTimeContextHolder {
* @param dateTimeContext the current DateTimeContext,
* or {@code null} to reset the thread-bound context
*/
public static void setDateTimeContext(DateTimeContext dateTimeContext) {
public static void setDateTimeContext(@Nullable DateTimeContext dateTimeContext) {
if (dateTimeContext == null) {
resetDateTimeContext();
}
@@ -59,6 +60,7 @@ public final class DateTimeContextHolder {
* Return the DateTimeContext associated with the current thread, if any.
* @return the current DateTimeContext, or {@code null} if none
*/
@Nullable
public static DateTimeContext getDateTimeContext() {
return dateTimeContextHolder.get();
}
@@ -71,7 +73,7 @@ public final class DateTimeContextHolder {
* @param locale the current user locale (may be {@code null} if not known)
* @return the user-specific DateTimeFormatter
*/
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, Locale locale) {
public static DateTimeFormatter getFormatter(DateTimeFormatter formatter, @Nullable Locale locale) {
DateTimeFormatter formatterToUse = (locale != null ? formatter.withLocale(locale) : formatter);
DateTimeContext context = getDateTimeContext();
return (context != null ? context.getFormatter(formatterToUse) : formatterToUse);

View File

@@ -22,6 +22,7 @@ import java.time.format.ResolverStyle;
import java.util.TimeZone;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -131,6 +132,7 @@ public class DateTimeFormatterFactory {
this.timeStyle = convertStyleCharacter(style.charAt(1));
}
@Nullable
private FormatStyle convertStyleCharacter(char c) {
switch (c) {
case 'S': return FormatStyle.SHORT;
@@ -170,7 +172,7 @@ public class DateTimeFormatterFactory {
* factory properties have been set (can be {@code null}).
* @return a new date time formatter
*/
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
public DateTimeFormatter createDateTimeFormatter(@Nullable DateTimeFormatter fallbackFormatter) {
DateTimeFormatter dateTimeFormatter = null;
if (StringUtils.hasLength(this.pattern)) {
// Using strict parsing to align with Joda-Time and standard DateFormat behavior:

View File

@@ -1,4 +1,7 @@
/**
* Integration with the JSR-310 <code>java.time</code> package in JDK 8.
*/
@NonNullApi
package org.springframework.format.datetime.standard;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Integration with the JSR-354 <code>javax.money</code> package.
*/
@NonNullApi
package org.springframework.format.number.money;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Formatters for {@code java.lang.Number} properties.
*/
@NonNullApi
package org.springframework.format.number;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* An API for defining Formatters to format field model values for display in a UI.
*/
@NonNullApi
package org.springframework.format;
import org.springframework.lang.NonNullApi;

View File

@@ -2,4 +2,7 @@
* Support classes for the formatting package,
* providing common implementations as well as adapters.
*/
@NonNullApi
package org.springframework.format.support;
import org.springframework.lang.NonNullApi;

View File

@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.instrument.InstrumentationSavingAgent;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -139,6 +140,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver {
* @return the Instrumentation instance, or {@code null} if none found
* @see #isInstrumentationAvailable()
*/
@Nullable
private static Instrumentation getInstrumentation() {
if (AGENT_CLASS_PRESENT) {
return InstrumentationAccessor.getInstrumentation();
@@ -175,6 +177,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver {
}
@Override
@Nullable
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

View File

@@ -1,4 +1,7 @@
/**
* Support for class instrumentation on GlassFish.
*/
@NonNullApi
package org.springframework.instrument.classloading.glassfish;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Support for class instrumentation on JBoss AS 6 and 7.
*/
@NonNullApi
package org.springframework.instrument.classloading.jboss;
import org.springframework.lang.NonNullApi;

View File

@@ -2,4 +2,7 @@
* Support package for load time weaving based on class loaders,
* as required by JPA providers (but not JPA-specific).
*/
@NonNullApi
package org.springframework.instrument.classloading;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Support for class instrumentation on Tomcat.
*/
@NonNullApi
package org.springframework.instrument.classloading.tomcat;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Support for class instrumentation on BEA WebLogic 10+.
*/
@NonNullApi
package org.springframework.instrument.classloading.weblogic;
import org.springframework.lang.NonNullApi;

View File

@@ -1,4 +1,7 @@
/**
* Support for class instrumentation on IBM WebSphere Application Server 7+.
*/
@NonNullApi
package org.springframework.instrument.classloading.websphere;
import org.springframework.lang.NonNullApi;

View File

@@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.jmx.MBeanServerNotFoundException;
import org.springframework.jmx.support.JmxUtils;
import org.springframework.lang.Nullable;
/**
* Internal helper class for managing a JMX connector.
@@ -49,7 +50,7 @@ class ConnectorDelegate {
* @param environment the JMX environment for the connector (may be {@code null})
* @param agentId the local JMX MBeanServer's agent id (may be {@code null})
*/
public MBeanServerConnection connect(JMXServiceURL serviceUrl, Map<String, ?> environment, String agentId)
public MBeanServerConnection connect(@Nullable JMXServiceURL serviceUrl, @Nullable Map<String, ?> environment, @Nullable String agentId)
throws MBeanServerNotFoundException {
if (serviceUrl != null) {

View File

@@ -61,6 +61,7 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.jmx.support.JmxUtils;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -224,6 +225,7 @@ public class MBeanClientInterceptor
* Return the management interface of the target MBean,
* or {@code null} if none specified.
*/
@Nullable
protected final Class<?> getManagementInterface() {
return this.managementInterface;
}
@@ -460,6 +462,7 @@ public class MBeanClientInterceptor
}
}
@Nullable
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
throws JMException, IOException {
@@ -527,7 +530,8 @@ public class MBeanClientInterceptor
* @return the converted result object, or the passed-in object if no conversion
* is necessary
*/
protected Object convertResultValueIfNecessary(Object result, MethodParameter parameter) {
@Nullable
protected Object convertResultValueIfNecessary(@Nullable Object result, MethodParameter parameter) {
Class<?> targetClass = parameter.getParameterType();
try {
if (result == null) {

View File

@@ -1,4 +1,7 @@
/**
* Provides support for accessing remote MBean resources.
*/
@NonNullApi
package org.springframework.jmx.access;
import org.springframework.lang.NonNullApi;

Some files were not shown because too many files have changed in this diff Show More