DATACMNS-1114 - Introduced usage of nullable annotations for API validation.
Marked all packages with Spring Frameworks @NonNullApi. Added Spring's @Nullable to methods, parameters and fields that take or produce null values. Adapted using code to make sure the IDE can evaluate the null flow properly. Fixed Javadoc in places where an invalid null handling policy was advertised. Strengthened null requirements for types that expose null-instances. Removed null handling from converters for JodaTime and ThreeTenBP. Introduced factory methods Page.empty() and Page.empty(Pageable). Introduced default methods getRequiredGetter(), …Setter() and …Field() on PersistentProperty to allow non-nullable lookups of members. The same for TypeInformation.getrequiredActualType(), …SuperTypeInformation(). Tweaked PersistentPropertyCreator.addPropertiesForRemainingDescriptors() to filter unsuitable PropertyDescriptors before actually trying to create a Property instance from them as the new stronger nullability requirements would cause exceptions downstream. Lazy.get() now expects a non-null return value. Clients being able to cope with null need to call ….orElse(…). Original pull request: #232.
This commit is contained in:
@@ -226,7 +226,7 @@ public class AuditingHandler implements InitializingBean {
|
||||
*/
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
if (auditorAware == null) {
|
||||
if (!auditorAware.isPresent()) {
|
||||
LOGGER.debug("No AuditorAware set! Auditing will not be applied!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.convert.ThreeTenBackPortConverters;
|
||||
import org.springframework.data.domain.Auditable;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -88,7 +89,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
|
||||
this.auditable = auditable;
|
||||
this.type = (Class<? extends TemporalAccessor>) ResolvableType.forClass(Auditable.class, auditable.getClass())
|
||||
.getGeneric(2).getRawClass();
|
||||
.getGeneric(2).resolve(TemporalAccessor.class);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -183,6 +184,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
* @param source must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
protected Object getDateValueToSet(TemporalAccessor value, Class<?> targetType, Object source) {
|
||||
|
||||
if (TemporalAccessor.class.equals(targetType)) {
|
||||
@@ -213,6 +215,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
* Returns the given object as {@link Calendar}.
|
||||
*
|
||||
* @param source can be {@literal null}.
|
||||
* @param target must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -299,7 +302,7 @@ class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory
|
||||
return getAsTemporalAccessor(metadata.getLastModifiedDateField().map(field -> {
|
||||
|
||||
Object value = org.springframework.util.ReflectionUtils.getField(field, target);
|
||||
return Optional.class.isInstance(value) ? ((Optional<?>) value).orElse(null) : value;
|
||||
return value instanceof Optional ? ((Optional<?>) value).orElse(null) : value;
|
||||
|
||||
}), TemporalAccessor.class);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.auditing.config;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
@@ -30,6 +31,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class AnnotationAuditingConfiguration implements AuditingConfiguration {
|
||||
|
||||
private static final String MISSING_ANNOTATION_ATTRIBUTES = "Couldn't find annotation attributes for %s in %s!";
|
||||
|
||||
private final AnnotationAttributes attributes;
|
||||
|
||||
/**
|
||||
@@ -44,7 +47,13 @@ public class AnnotationAuditingConfiguration implements AuditingConfiguration {
|
||||
Assert.notNull(metadata, "AnnotationMetadata must not be null!");
|
||||
Assert.notNull(annotation, "Annotation must not be null!");
|
||||
|
||||
this.attributes = new AnnotationAttributes(metadata.getAnnotationAttributes(annotation.getName()));
|
||||
Map<String, Object> attributesSource = metadata.getAnnotationAttributes(annotation.getName());
|
||||
|
||||
if (attributesSource == null) {
|
||||
throw new IllegalArgumentException(String.format(MISSING_ANNOTATION_ATTRIBUTES, annotation, metadata));
|
||||
}
|
||||
|
||||
this.attributes = new AnnotationAttributes(attributesSource);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.auditing.config;
|
||||
|
||||
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactoryBean;
|
||||
import org.springframework.aop.target.LazyInitTargetSource;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -51,6 +53,7 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
|
||||
*
|
||||
* @param mappingContextBeanName must not be {@literal null} or empty.
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
public AuditingHandlerBeanDefinitionParser(String mappingContextBeanName) {
|
||||
|
||||
Assert.hasText(mappingContextBeanName, "MappingContext bean name must not be null!");
|
||||
@@ -70,6 +73,7 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#getBeanClass(org.w3c.dom.Element)
|
||||
*/
|
||||
@Nonnull
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return AuditingHandler.class;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Types to abstract authentication concepts.
|
||||
*/
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.auditing.config;
|
||||
@@ -1,4 +1,5 @@
|
||||
/**
|
||||
* General support for entity auditing.
|
||||
*/
|
||||
package org.springframework.data.auditing;
|
||||
@org.springframework.lang.NonNullApi
|
||||
package org.springframework.data.auditing;
|
||||
|
||||
Reference in New Issue
Block a user