Changed signature of convertValue() to keep the Sun compiler happy
This commit is contained in:
parent
362629d03b
commit
707d2ed72a
|
|
@ -48,7 +48,7 @@ public interface TypeConverter {
|
|||
* @return the converted value
|
||||
* @throws EvaluationException if conversion is not possible
|
||||
*/
|
||||
<T> T convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException;
|
||||
Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Return true if the type converter can convert the specified type to the desired target type.
|
||||
|
|
|
|||
|
|
@ -100,11 +100,11 @@ public class ExpressionState {
|
|||
return this.relatedContext.getTypeLocator().findType(type);
|
||||
}
|
||||
|
||||
public <T> T convertValue(Object value, TypeDescriptor targetTypeDescriptor) throws EvaluationException {
|
||||
public Object convertValue(Object value, TypeDescriptor targetTypeDescriptor) throws EvaluationException {
|
||||
return this.relatedContext.getTypeConverter().convertValue(value, targetTypeDescriptor);
|
||||
}
|
||||
|
||||
public <T> T convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException {
|
||||
public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException {
|
||||
return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public class ConstructorReference extends SpelNodeImpl {
|
|||
TypedValue childValue = getChild(i + 1).getValueInternal(state);
|
||||
Object value = childValue.getValue();
|
||||
arguments[i] = value;
|
||||
argumentTypes[i] = value==null?Object.class:value.getClass();
|
||||
argumentTypes[i] = (value==null?Object.class:value.getClass());
|
||||
}
|
||||
|
||||
ConstructorExecutor executorToUse = this.cachedExecutor;
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class Indexer extends SpelNodeImpl {
|
|||
return new TypedValue(o,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapValueType()));
|
||||
}
|
||||
|
||||
int idx = state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
|
||||
if (targetObject == null) {
|
||||
throw new SpelException(SpelMessages.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||
|
|
@ -115,10 +115,10 @@ public class Indexer extends SpelNodeImpl {
|
|||
}
|
||||
|
||||
if (targetObjectTypeDescriptor.isArray()) {
|
||||
int idx = state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
setArrayElement(state, contextObject.getValue(), idx, newValue, targetObjectTypeDescriptor.getElementType());
|
||||
} else if (targetObjectTypeDescriptor.isCollection()) {
|
||||
int idx = state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
int idx = (Integer)state.convertValue(index, INTEGER_TYPE_DESCRIPTOR);
|
||||
Collection c = (Collection) targetObject;
|
||||
if (idx >= c.size()) {
|
||||
throw new SpelException(SpelMessages.COLLECTION_INDEX_OUT_OF_BOUNDS, c.size(), idx);
|
||||
|
|
@ -153,35 +153,35 @@ public class Indexer extends SpelNodeImpl {
|
|||
if (arrayComponentType == Integer.TYPE) {
|
||||
int[] array = (int[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, INTEGER_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Integer)state.convertValue(newValue, INTEGER_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Boolean.TYPE) {
|
||||
boolean[] array = (boolean[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Boolean)state.convertValue(newValue, BOOLEAN_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Character.TYPE) {
|
||||
char[] array = (char[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, CHARACTER_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Character)state.convertValue(newValue, CHARACTER_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Long.TYPE) {
|
||||
long[] array = (long[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, LONG_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Long)state.convertValue(newValue, LONG_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Short.TYPE) {
|
||||
short[] array = (short[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, SHORT_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Short)state.convertValue(newValue, SHORT_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Double.TYPE) {
|
||||
double[] array = (double[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, DOUBLE_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Double)state.convertValue(newValue, DOUBLE_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Float.TYPE) {
|
||||
float[] array = (float[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, FLOAT_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Float)state.convertValue(newValue, FLOAT_TYPE_DESCRIPTOR);
|
||||
} else if (arrayComponentType == Byte.TYPE) {
|
||||
byte[] array = (byte[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
array[idx] = state.convertValue(newValue, BYTE_TYPE_DESCRIPTOR);
|
||||
array[idx] = (Byte)state.convertValue(newValue, BYTE_TYPE_DESCRIPTOR);
|
||||
} else {
|
||||
Object[] array = (Object[]) ctx;
|
||||
checkAccess(array.length, idx);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class OperatorAnd extends Operator {
|
|||
boolean rightValue;
|
||||
|
||||
try {
|
||||
leftValue = state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
leftValue = (Boolean)state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
}
|
||||
catch (SpelException ee) {
|
||||
ee.setPosition(getLeftOperand().getCharPositionInLine());
|
||||
|
|
@ -58,7 +58,7 @@ public class OperatorAnd extends Operator {
|
|||
}
|
||||
|
||||
try {
|
||||
rightValue = state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
rightValue = (Boolean)state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
}
|
||||
catch (SpelException ee) {
|
||||
ee.setPosition(getRightOperand().getCharPositionInLine());
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class OperatorNot extends SpelNodeImpl { // Not is a unary operator so do
|
|||
@Override
|
||||
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
|
||||
try {
|
||||
boolean value = state.convertValue(getChild(0).getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
boolean value = (Boolean)state.convertValue(getChild(0).getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
return BooleanTypedValue.forValue(!value);
|
||||
}
|
||||
catch (SpelException see) {
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ public class OperatorOr extends Operator {
|
|||
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
|
||||
boolean leftValue;
|
||||
boolean rightValue;
|
||||
try {
|
||||
leftValue = state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
try {
|
||||
leftValue = (Boolean)state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
}
|
||||
catch (SpelException see) {
|
||||
see.setPosition(getLeftOperand().getCharPositionInLine());
|
||||
|
|
@ -56,7 +56,7 @@ public class OperatorOr extends Operator {
|
|||
}
|
||||
|
||||
try {
|
||||
rightValue = state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
rightValue = (Boolean)state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
|
||||
}
|
||||
catch (SpelException see) {
|
||||
see.setPosition(getRightOperand().getCharPositionInLine());
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class StandardTypeConverter implements TypeConverter {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException {
|
||||
public Object convertValue(Object value, TypeDescriptor typeDescriptor) throws EvaluationException {
|
||||
// For activation when conversion service available - this replaces the rest of the method (probably...)
|
||||
// try {
|
||||
// return (T)conversionService.executeConversion(value, typeDescriptor);
|
||||
|
|
@ -95,7 +95,7 @@ public class StandardTypeConverter implements TypeConverter {
|
|||
// } catch (ConversionException ce) {
|
||||
// throw new SpelException(ce, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString());
|
||||
// }
|
||||
return (T)convertValue(value,typeDescriptor.getType());
|
||||
return convertValue(value,typeDescriptor.getType());
|
||||
}
|
||||
|
||||
public boolean canConvert(Class<?> sourceType, Class<?> targetType) {
|
||||
|
|
|
|||
|
|
@ -111,9 +111,9 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T convertValue(Object value, TypeDescriptor typeDescriptor)
|
||||
public Object convertValue(Object value, TypeDescriptor typeDescriptor)
|
||||
throws EvaluationException {
|
||||
return (T)super.executeConversion(value, typeDescriptor);
|
||||
return super.executeConversion(value, typeDescriptor);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.expression.spel;
|
||||
|
||||
/**
|
||||
* Tests based on Jiras up to the release of Spring 3.0.0
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class SpringEL300Tests extends ExpressionTestCase {
|
||||
|
||||
public void testNPE_5661() {
|
||||
evaluate("joinThreeStrings('a',null,'c')", "anullc", String.class);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue