Add more @Nullable parameters based on null usage
Issue: SPR-15540
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.expression;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ public class TypedValue {
|
||||
* is inferred from the object, so no generic declarations are preserved.
|
||||
* @param value the object value
|
||||
*/
|
||||
public TypedValue(Object value) {
|
||||
public TypedValue(@Nullable Object value) {
|
||||
this.value = value;
|
||||
this.typeDescriptor = null; // initialized when/if requested
|
||||
}
|
||||
@@ -54,12 +55,13 @@ public class TypedValue {
|
||||
* @param value the object value
|
||||
* @param typeDescriptor a type descriptor describing the type of the value
|
||||
*/
|
||||
public TypedValue(Object value, TypeDescriptor typeDescriptor) {
|
||||
public TypedValue(@Nullable Object value, @Nullable TypeDescriptor typeDescriptor) {
|
||||
this.value = value;
|
||||
this.typeDescriptor = typeDescriptor;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -44,7 +45,7 @@ public abstract class ExpressionUtils {
|
||||
* of the value to the specified type is not supported
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T convertTypedValue(EvaluationContext context, TypedValue typedValue, Class<T> targetType) {
|
||||
public static <T> T convertTypedValue(@Nullable EvaluationContext context, TypedValue typedValue, Class<T> targetType) {
|
||||
Object value = typedValue.getValue();
|
||||
if (targetType == null) {
|
||||
return (T) value;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.ParserContext;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* An expression parser that understands templates. It can be subclassed by expression
|
||||
@@ -255,7 +256,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
|
||||
* @return an evaluator for the parsed expression
|
||||
* @throws ParseException an exception occurred during parsing
|
||||
*/
|
||||
protected abstract Expression doParseExpression(String expressionString, ParserContext context)
|
||||
protected abstract Expression doParseExpression(String expressionString, @Nullable ParserContext context)
|
||||
throws ParseException;
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.expression.spel;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Base superclass for compiled expressions. Each generated compiled expression class
|
||||
@@ -33,6 +34,6 @@ public abstract class CompiledExpression {
|
||||
* Subclasses of CompiledExpression generated by SpelCompiler will provide an
|
||||
* implementation of this method.
|
||||
*/
|
||||
public abstract Object getValue(Object target, EvaluationContext context) throws EvaluationException;
|
||||
public abstract Object getValue(Object target, @Nullable EvaluationContext context) throws EvaluationException;
|
||||
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class ExpressionState {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TypedValue operate(Operation op, Object left, Object right) throws EvaluationException {
|
||||
public TypedValue operate(Operation op, Object left, @Nullable Object right) throws EvaluationException {
|
||||
OperatorOverloader overloader = this.relatedContext.getOperatorOverloader();
|
||||
if (overloader.overridesOperation(op, left, right)) {
|
||||
Object returnValue = overloader.operate(op, left, right);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
import org.springframework.core.SpringProperties;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
@@ -62,7 +63,7 @@ public class SpelParserConfiguration {
|
||||
* @param compilerMode the compiler mode for the parser
|
||||
* @param compilerClassLoader the ClassLoader to use as the basis for expression compilation
|
||||
*/
|
||||
public SpelParserConfiguration(SpelCompilerMode compilerMode, ClassLoader compilerClassLoader) {
|
||||
public SpelParserConfiguration(@Nullable SpelCompilerMode compilerMode, ClassLoader compilerClassLoader) {
|
||||
this(compilerMode, compilerClassLoader, false, false, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.expression.spel.ast;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,7 @@ public class FormatHelper {
|
||||
* @return a formatted String suitable for message inclusion
|
||||
* @see ClassUtils#getQualifiedName(Class)
|
||||
*/
|
||||
public static String formatClassNameForMessage(Class<?> clazz) {
|
||||
public static String formatClassNameForMessage(@Nullable Class<?> clazz) {
|
||||
return (clazz != null ? ClassUtils.getQualifiedName(clazz) : "null");
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
|
||||
|
||||
@Override
|
||||
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
|
||||
protected SpelExpression doParseExpression(String expressionString, @Nullable ParserContext context) throws ParseException {
|
||||
try {
|
||||
this.expressionString = expressionString;
|
||||
Tokenizer tokenizer = new Tokenizer(expressionString);
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.expression.ParseException;
|
||||
import org.springframework.expression.ParserContext;
|
||||
import org.springframework.expression.common.TemplateAwareExpressionParser;
|
||||
import org.springframework.expression.spel.SpelParserConfiguration;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -56,7 +57,7 @@ public class SpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpelExpression doParseExpression(String expressionString, ParserContext context) throws ParseException {
|
||||
protected SpelExpression doParseExpression(String expressionString, @Nullable ParserContext context) throws ParseException {
|
||||
return new InternalSpelExpressionParser(this.configuration).doParseExpression(expressionString, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.expression.TypeComparator;
|
||||
import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.TypeLocator;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -84,7 +85,7 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
this.rootObject = new TypedValue(rootObject, typeDescriptor);
|
||||
}
|
||||
|
||||
public void setRootObject(Object rootObject) {
|
||||
public void setRootObject(@Nullable Object rootObject) {
|
||||
this.rootObject = (rootObject != null ? new TypedValue(rootObject) : TypedValue.NULL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user