Make SpEL rootObject parameter nullable
Closes gh-23442
This commit is contained in:
@@ -63,7 +63,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
@Nullable
|
||||
Object getValue(Object rootObject) throws EvaluationException;
|
||||
Object getValue(@Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate the expression in the default context against the specified root
|
||||
@@ -75,7 +75,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
@Nullable
|
||||
<T> T getValue(Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException;
|
||||
<T> T getValue(@Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate this expression in the provided context and return the result
|
||||
@@ -97,7 +97,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
@Nullable
|
||||
Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
Object getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate the expression in a specified context which can resolve references
|
||||
@@ -125,7 +125,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
@Nullable
|
||||
<T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
<T> T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
throws EvaluationException;
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem determining the type
|
||||
*/
|
||||
@Nullable
|
||||
Class<?> getValueType(Object rootObject) throws EvaluationException;
|
||||
Class<?> getValueType(@Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Return the most general type that can be passed to the
|
||||
@@ -167,7 +167,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem determining the type
|
||||
*/
|
||||
@Nullable
|
||||
Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
Class<?> getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Return the most general type that can be passed to a {@link #setValue}
|
||||
@@ -186,7 +186,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem determining the type
|
||||
*/
|
||||
@Nullable
|
||||
TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException;
|
||||
TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Return the most general type that can be passed to the
|
||||
@@ -208,7 +208,7 @@ public interface Expression {
|
||||
* @throws EvaluationException if there is a problem determining the type
|
||||
*/
|
||||
@Nullable
|
||||
TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Determine if an expression can be written to, i.e. setValue() can be called.
|
||||
@@ -216,7 +216,7 @@ public interface Expression {
|
||||
* @return {@code true} if the expression is writable; {@code false} otherwise
|
||||
* @throws EvaluationException if there is a problem determining if it is writable
|
||||
*/
|
||||
boolean isWritable(Object rootObject) throws EvaluationException;
|
||||
boolean isWritable(@Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Determine if an expression can be written to, i.e. setValue() can be called.
|
||||
@@ -234,7 +234,7 @@ public interface Expression {
|
||||
* @return {@code true} if the expression is writable; {@code false} otherwise
|
||||
* @throws EvaluationException if there is a problem determining if it is writable
|
||||
*/
|
||||
boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
boolean isWritable(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
@@ -242,7 +242,7 @@ public interface Expression {
|
||||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(Object rootObject, @Nullable Object value) throws EvaluationException;
|
||||
void setValue(@Nullable Object rootObject, @Nullable Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
@@ -260,6 +260,6 @@ public interface Expression {
|
||||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException;
|
||||
void setValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Object value) throws EvaluationException;
|
||||
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(Object rootObject) throws EvaluationException {
|
||||
public String getValue(@Nullable Object rootObject) throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Expression expression : this.expressions) {
|
||||
String value = expression.getValue(rootObject, String.class);
|
||||
@@ -96,7 +96,7 @@ public class CompositeStringExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getValue(Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException {
|
||||
public <T> T getValue(@Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(rootObject);
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public String getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Expression expression : this.expressions) {
|
||||
String value = expression.getValue(context, rootObject, String.class);
|
||||
@@ -136,7 +136,7 @@ public class CompositeStringExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
public <T> T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Object value = getValue(context,rootObject);
|
||||
@@ -154,12 +154,12 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(@Nullable Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
public TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@@ -179,14 +179,14 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject)
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject)
|
||||
throws EvaluationException {
|
||||
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
public boolean isWritable(@Nullable Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -196,12 +196,12 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public boolean isWritable(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
public void setValue(@Nullable Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class CompositeStringExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
public void setValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
}
|
||||
|
||||
|
||||
@@ -67,13 +67,13 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(Object rootObject) {
|
||||
public String getValue(@Nullable Object rootObject) {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getValue(Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException {
|
||||
public <T> T getValue(@Nullable Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(rootObject);
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
@@ -93,13 +93,13 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public String getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
public <T> T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Object value = getValue(context, rootObject);
|
||||
@@ -112,12 +112,12 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(@Nullable Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
public TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@@ -137,12 +137,12 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
public boolean isWritable(@Nullable Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -152,12 +152,12 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public boolean isWritable(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
public void setValue(@Nullable Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class LiteralExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
public void setValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getValue(Object rootObject) throws EvaluationException {
|
||||
public Object getValue(@Nullable Object rootObject) throws EvaluationException {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
return this.compiledAst.getValue(rootObject, getEvaluationContext());
|
||||
@@ -208,7 +208,7 @@ public class SpelExpression implements Expression {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getValue(Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
public <T> T getValue(@Nullable Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
Object result = this.compiledAst.getValue(rootObject, getEvaluationContext());
|
||||
@@ -306,7 +306,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public Object getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
|
||||
if (this.compiledAst != null) {
|
||||
@@ -335,7 +335,7 @@ public class SpelExpression implements Expression {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> expectedResultType)
|
||||
public <T> T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class<T> expectedResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
@@ -377,7 +377,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?> getValueType(Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(@Nullable Object rootObject) throws EvaluationException {
|
||||
return getValueType(getEvaluationContext(), rootObject);
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Class<?> getValueType(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public Class<?> getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration);
|
||||
TypeDescriptor typeDescriptor = this.ast.getValueInternal(expressionState).getTypeDescriptor();
|
||||
return (typeDescriptor != null ? typeDescriptor.getType() : null);
|
||||
@@ -406,7 +406,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
public TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException {
|
||||
ExpressionState expressionState =
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
|
||||
return this.ast.getValueInternal(expressionState).getTypeDescriptor();
|
||||
@@ -422,7 +422,7 @@ public class SpelExpression implements Expression {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject)
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject)
|
||||
throws EvaluationException {
|
||||
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
@@ -431,7 +431,7 @@ public class SpelExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
public boolean isWritable(@Nullable Object rootObject) throws EvaluationException {
|
||||
return this.ast.isWritable(
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration));
|
||||
}
|
||||
@@ -443,13 +443,13 @@ public class SpelExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public boolean isWritable(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException {
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
return this.ast.isWritable(new ExpressionState(context, toTypedValue(rootObject), this.configuration));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
public void setValue(@Nullable Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
this.ast.setValue(
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration), value);
|
||||
}
|
||||
@@ -461,7 +461,7 @@ public class SpelExpression implements Expression {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value)
|
||||
public void setValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Object value)
|
||||
throws EvaluationException {
|
||||
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
|
||||
@@ -103,12 +103,12 @@ public class StandardEvaluationContext implements EvaluationContext {
|
||||
* @param rootObject the root object to use
|
||||
* @see #setRootObject
|
||||
*/
|
||||
public StandardEvaluationContext(Object rootObject) {
|
||||
public StandardEvaluationContext(@Nullable Object rootObject) {
|
||||
this.rootObject = new TypedValue(rootObject);
|
||||
}
|
||||
|
||||
|
||||
public void setRootObject(Object rootObject, TypeDescriptor typeDescriptor) {
|
||||
public void setRootObject(@Nullable Object rootObject, TypeDescriptor typeDescriptor) {
|
||||
this.rootObject = new TypedValue(rootObject, typeDescriptor);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user