Perform NullAway build-time checks in spring-expression
See gh-32475
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user