diff --git a/spring-expression/src/main/java/org/springframework/expression/Expression.java b/spring-expression/src/main/java/org/springframework/expression/Expression.java index 7c5fb84544..8babd78243 100644 --- a/spring-expression/src/main/java/org/springframework/expression/Expression.java +++ b/spring-expression/src/main/java/org/springframework/expression/Expression.java @@ -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 getValue(Object rootObject, @Nullable Class desiredResultType) throws EvaluationException; + T getValue(@Nullable Object rootObject, @Nullable Class 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 getValue(EvaluationContext context, Object rootObject, @Nullable Class desiredResultType) + T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class 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; } diff --git a/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java b/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java index b5d2c33c83..a37cb2162e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java @@ -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 getValue(Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { + public T getValue(@Nullable Object rootObject, @Nullable Class 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 getValue(EvaluationContext context, Object rootObject, @Nullable Class desiredResultType) + public T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class 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"); } diff --git a/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java b/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java index 75bf6aac6b..07c64bd9f6 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java @@ -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 getValue(Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { + public T getValue(@Nullable Object rootObject, @Nullable Class 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 getValue(EvaluationContext context, Object rootObject, @Nullable Class desiredResultType) + public T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class 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"); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java index 386d69caac..870a523266 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java @@ -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 getValue(Object rootObject, @Nullable Class expectedResultType) throws EvaluationException { + public T getValue(@Nullable Object rootObject, @Nullable Class 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 getValue(EvaluationContext context, Object rootObject, @Nullable Class expectedResultType) + public T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class 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"); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java index ddee43bd18..7cde54692e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java @@ -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); }