DATACMNS-1271 - Streamlined implementation of AnnotationBasedPersistentProperty to avoid NullPointerExceptions.

We now use the annotation cache's ….computeIfAbsent(…) to avoid inconsistencies between ….contains(…) and ….get(…) in multi-threaded scenarios.
This commit is contained in:
Oliver Gierke
2018-03-01 16:09:21 +01:00
parent ff22d0cda5
commit 32ea1f77c0
2 changed files with 19 additions and 27 deletions

View File

@@ -28,6 +28,7 @@ import java.util.stream.Collector;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
@@ -95,4 +96,15 @@ public interface StreamUtils {
Function<T, V> valueFunction) {
return MultiValueMapCollector.of(keyFunction, valueFunction);
}
/**
* Creates a new {@link Stream} for the given value returning an empty {@link Stream} if the value is {@literal null}.
*
* @param source can be {@literal null}.
* @return a new {@link Stream} for the given value returning an empty {@link Stream} if the value is {@literal null}.
* @since 2.0.6
*/
public static <T> Stream<T> fromNullable(@Nullable T source) {
return source == null ? Stream.empty() : Stream.of(source);
}
}