Perform NullAway build-time checks in spring-expression

See gh-32475
This commit is contained in:
Sébastien Deleuze
2024-03-20 10:09:04 +01:00
parent 1ccd5512c5
commit f648fd7c3b
14 changed files with 41 additions and 12 deletions

View File

@@ -30,6 +30,7 @@ import java.util.stream.Stream;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Contract;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -562,6 +563,7 @@ public class TypeDescriptor implements Serializable {
* @return the type descriptor
*/
@Nullable
@Contract("!null -> !null; null -> null")
public static TypeDescriptor forObject(@Nullable Object source) {
return (source != null ? valueOf(source.getClass()) : null);
}

View File

@@ -312,6 +312,7 @@ public abstract class Assert {
* @param message the exception message to use if the assertion fails
* @throws IllegalArgumentException if the object array is {@code null} or contains no elements
*/
@Contract("null, _ -> fail")
public static void notEmpty(@Nullable Object[] array, String message) {
if (ObjectUtils.isEmpty(array)) {
throw new IllegalArgumentException(message);
@@ -330,6 +331,7 @@ public abstract class Assert {
* @throws IllegalArgumentException if the object array is {@code null} or contains no elements
* @since 5.0
*/
@Contract("null, _ -> fail")
public static void notEmpty(@Nullable Object[] array, Supplier<String> messageSupplier) {
if (ObjectUtils.isEmpty(array)) {
throw new IllegalArgumentException(nullSafeGet(messageSupplier));

View File

@@ -27,6 +27,7 @@ import java.util.Optional;
import java.util.StringJoiner;
import java.util.TimeZone;
import org.springframework.lang.Contract;
import org.springframework.lang.Nullable;
/**
@@ -110,6 +111,7 @@ public abstract class ObjectUtils {
* @param array the array to check
* @see #isEmpty(Object)
*/
@Contract("null -> true")
public static boolean isEmpty(@Nullable Object[] array) {
return (array == null || array.length == 0);
}
@@ -331,6 +333,7 @@ public abstract class ObjectUtils {
* @see Object#equals(Object)
* @see java.util.Arrays#equals
*/
@Contract("null, null -> true; null, _ -> false; _, null -> false")
public static boolean nullSafeEquals(@Nullable Object o1, @Nullable Object o2) {
if (o1 == o2) {
return true;