TypedValue.NULL_TYPED_VALUE -> TypedValue.NULL
This commit is contained in:
parent
dc99df2972
commit
2ec39f5000
|
|
@ -28,13 +28,13 @@ import org.springframework.core.convert.TypeDescriptor;
|
|||
*/
|
||||
public class TypedValue {
|
||||
|
||||
public static final TypedValue NULL_TYPED_VALUE = new TypedValue(null, TypeDescriptor.NULL);
|
||||
public static final TypedValue NULL = new TypedValue(null, TypeDescriptor.NULL);
|
||||
|
||||
|
||||
private final Object value;
|
||||
|
||||
private TypeDescriptor typeDescriptor;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a TypedValue for a simple object. The type descriptor is inferred
|
||||
|
|
@ -43,9 +43,9 @@ public class TypedValue {
|
|||
*/
|
||||
public TypedValue(Object value) {
|
||||
this.value = value;
|
||||
this.typeDescriptor = null;// initialized when/if requested
|
||||
this.typeDescriptor = null; // initialized when/if requested
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a TypedValue for a particular value with a particular type descriptor.
|
||||
* @param value the object value
|
||||
|
|
@ -62,8 +62,8 @@ public class TypedValue {
|
|||
}
|
||||
|
||||
public TypeDescriptor getTypeDescriptor() {
|
||||
if (this.typeDescriptor==null) {
|
||||
this.typeDescriptor = TypeDescriptor.forObject(value);
|
||||
if (this.typeDescriptor == null) {
|
||||
this.typeDescriptor = TypeDescriptor.forObject(this.value);
|
||||
}
|
||||
return this.typeDescriptor;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class ExpressionState {
|
|||
public TypedValue lookupVariable(String name) {
|
||||
Object value = this.relatedContext.lookupVariable(name);
|
||||
if (value == null) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
}
|
||||
else {
|
||||
return new TypedValue(value, TypeDescriptor.forObject(value));
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class MethodReference extends SpelNodeImpl {
|
|||
}
|
||||
if (currentContext.getValue() == null) {
|
||||
if (nullSafe) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
} else {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED,
|
||||
FormatHelper.formatMethodForMessage(name, getTypes(arguments)));
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class NullLiteral extends Literal {
|
|||
|
||||
@Override
|
||||
public TypedValue getLiteralValue() {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class OpAnd extends Operator {
|
|||
}
|
||||
|
||||
private void assertTypedValueNotNull(TypedValue typedValue) {
|
||||
if (TypedValue.NULL_TYPED_VALUE.equals(typedValue)) {
|
||||
if (TypedValue.NULL.equals(typedValue)) {
|
||||
throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class OpOr extends Operator {
|
|||
}
|
||||
|
||||
private void assertTypedValueNotNull(TypedValue typedValue) {
|
||||
if (TypedValue.NULL_TYPED_VALUE.equals(typedValue)) {
|
||||
if (TypedValue.NULL.equals(typedValue)) {
|
||||
throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class OperatorNot extends SpelNodeImpl { // Not is a unary operator so do
|
|||
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
|
||||
try {
|
||||
TypedValue typedValue = children[0].getValueInternal(state);
|
||||
if (TypedValue.NULL_TYPED_VALUE.equals(typedValue)) {
|
||||
if (TypedValue.NULL.equals(typedValue)) {
|
||||
throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
|
||||
}
|
||||
boolean value = (Boolean) state.convertValue(typedValue, TypeDescriptor.valueOf(Boolean.class));
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class Projection extends SpelNodeImpl {
|
|||
} else {
|
||||
if (operand==null) {
|
||||
if (nullSafe) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
} else {
|
||||
throw new SpelEvaluationException(getStartPosition(),SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, "null");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public class PropertyOrFieldReference extends SpelNodeImpl {
|
|||
Object targetObject = contextObject.getValue();
|
||||
|
||||
if (targetObject == null && nullSafe) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
}
|
||||
|
||||
PropertyAccessor accessorToUse = this.cachedReadAccessor;
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ public class Selection extends SpelNodeImpl {
|
|||
}
|
||||
}
|
||||
if ((variant == FIRST || variant == LAST) && result.size() == 0) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
}
|
||||
if (variant == LAST) {
|
||||
return new TypedValue(result.get(result.size() - 1),TypeDescriptor.valueOf(op.getTypeDescriptor().getElementType()));
|
||||
|
|
@ -150,7 +150,7 @@ public class Selection extends SpelNodeImpl {
|
|||
} else {
|
||||
if (operand==null) {
|
||||
if (nullSafe) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
} else {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INVALID_TYPE_FOR_SELECTION,
|
||||
"null");
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ public class SpelExpression implements Expression {
|
|||
|
||||
private TypedValue toTypedValue(Object object) {
|
||||
if (object == null) {
|
||||
return TypedValue.NULL_TYPED_VALUE;
|
||||
return TypedValue.NULL;
|
||||
}
|
||||
else {
|
||||
return new TypedValue(object);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class StandardEvaluationContext implements EvaluationContext {
|
|||
|
||||
public void setRootObject(Object rootObject) {
|
||||
if (this.rootObject == null) {
|
||||
this.rootObject = TypedValue.NULL_TYPED_VALUE;
|
||||
this.rootObject = TypedValue.NULL;
|
||||
} else {
|
||||
this.rootObject = new TypedValue(rootObject);//, TypeDescriptor.forObject(rootObject));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
|||
public void testVariables() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL_TYPED_VALUE,typedValue);
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
state.setVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
|
|
@ -85,11 +85,11 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
|||
public void testNoVariableInteference() {
|
||||
ExpressionState state = getState();
|
||||
TypedValue typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL_TYPED_VALUE,typedValue);
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
state.setLocalVariable("foo",34);
|
||||
typedValue = state.lookupVariable("foo");
|
||||
Assert.assertEquals(TypedValue.NULL_TYPED_VALUE,typedValue);
|
||||
Assert.assertEquals(TypedValue.NULL,typedValue);
|
||||
|
||||
state.setVariable("goo","hello");
|
||||
Assert.assertNull(state.lookupLocalVariable("goo"));
|
||||
|
|
@ -124,7 +124,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
|||
// Assert.assertEquals(null, state.getRootContextObject().getValue());
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
Assert.assertEquals(TypedValue.NULL_TYPED_VALUE,state.getRootContextObject());
|
||||
Assert.assertEquals(TypedValue.NULL,state.getRootContextObject());
|
||||
|
||||
|
||||
((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null,TypeDescriptor.NULL);
|
||||
|
|
@ -156,7 +156,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
|
|||
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
|
||||
|
||||
state = new ExpressionState(new StandardEvaluationContext());
|
||||
Assert.assertEquals(TypedValue.NULL_TYPED_VALUE,state.getActiveContextObject());
|
||||
Assert.assertEquals(TypedValue.NULL,state.getActiveContextObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue