Changed signature of convertValue() to keep the Sun compiler happy

This commit is contained in:
Andy Clement 2009-04-09 16:00:53 +00:00
parent 362629d03b
commit 707d2ed72a
10 changed files with 55 additions and 25 deletions

View File

@ -48,7 +48,7 @@ public interface TypeConverter {
* @return the converted value * @return the converted value
* @throws EvaluationException if conversion is not possible * @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. * Return true if the type converter can convert the specified type to the desired target type.

View File

@ -100,11 +100,11 @@ public class ExpressionState {
return this.relatedContext.getTypeLocator().findType(type); 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); 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); return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor);
} }

View File

@ -76,7 +76,7 @@ public class ConstructorReference extends SpelNodeImpl {
TypedValue childValue = getChild(i + 1).getValueInternal(state); TypedValue childValue = getChild(i + 1).getValueInternal(state);
Object value = childValue.getValue(); Object value = childValue.getValue();
arguments[i] = value; arguments[i] = value;
argumentTypes[i] = value==null?Object.class:value.getClass(); argumentTypes[i] = (value==null?Object.class:value.getClass());
} }
ConstructorExecutor executorToUse = this.cachedExecutor; ConstructorExecutor executorToUse = this.cachedExecutor;

View File

@ -58,7 +58,7 @@ public class Indexer extends SpelNodeImpl {
return new TypedValue(o,TypeDescriptor.valueOf(targetObjectTypeDescriptor.getMapValueType())); 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) { if (targetObject == null) {
throw new SpelException(SpelMessages.CANNOT_INDEX_INTO_NULL_VALUE); throw new SpelException(SpelMessages.CANNOT_INDEX_INTO_NULL_VALUE);
@ -115,10 +115,10 @@ public class Indexer extends SpelNodeImpl {
} }
if (targetObjectTypeDescriptor.isArray()) { 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()); setArrayElement(state, contextObject.getValue(), idx, newValue, targetObjectTypeDescriptor.getElementType());
} else if (targetObjectTypeDescriptor.isCollection()) { } 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; Collection c = (Collection) targetObject;
if (idx >= c.size()) { if (idx >= c.size()) {
throw new SpelException(SpelMessages.COLLECTION_INDEX_OUT_OF_BOUNDS, c.size(), idx); 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) { if (arrayComponentType == Integer.TYPE) {
int[] array = (int[]) ctx; int[] array = (int[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Boolean.TYPE) {
boolean[] array = (boolean[]) ctx; boolean[] array = (boolean[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Character.TYPE) {
char[] array = (char[]) ctx; char[] array = (char[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Long.TYPE) {
long[] array = (long[]) ctx; long[] array = (long[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Short.TYPE) {
short[] array = (short[]) ctx; short[] array = (short[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Double.TYPE) {
double[] array = (double[]) ctx; double[] array = (double[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Float.TYPE) {
float[] array = (float[]) ctx; float[] array = (float[]) ctx;
checkAccess(array.length, idx); 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) { } else if (arrayComponentType == Byte.TYPE) {
byte[] array = (byte[]) ctx; byte[] array = (byte[]) ctx;
checkAccess(array.length, idx); checkAccess(array.length, idx);
array[idx] = state.convertValue(newValue, BYTE_TYPE_DESCRIPTOR); array[idx] = (Byte)state.convertValue(newValue, BYTE_TYPE_DESCRIPTOR);
} else { } else {
Object[] array = (Object[]) ctx; Object[] array = (Object[]) ctx;
checkAccess(array.length, idx); checkAccess(array.length, idx);

View File

@ -46,7 +46,7 @@ public class OperatorAnd extends Operator {
boolean rightValue; boolean rightValue;
try { try {
leftValue = state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR); leftValue = (Boolean)state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
} }
catch (SpelException ee) { catch (SpelException ee) {
ee.setPosition(getLeftOperand().getCharPositionInLine()); ee.setPosition(getLeftOperand().getCharPositionInLine());
@ -58,7 +58,7 @@ public class OperatorAnd extends Operator {
} }
try { try {
rightValue = state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR); rightValue = (Boolean)state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
} }
catch (SpelException ee) { catch (SpelException ee) {
ee.setPosition(getRightOperand().getCharPositionInLine()); ee.setPosition(getRightOperand().getCharPositionInLine());

View File

@ -37,7 +37,7 @@ public class OperatorNot extends SpelNodeImpl { // Not is a unary operator so do
@Override @Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
try { 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); return BooleanTypedValue.forValue(!value);
} }
catch (SpelException see) { catch (SpelException see) {

View File

@ -44,7 +44,7 @@ public class OperatorOr extends Operator {
boolean leftValue; boolean leftValue;
boolean rightValue; boolean rightValue;
try { try {
leftValue = state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR); leftValue = (Boolean)state.convertValue(getLeftOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
} }
catch (SpelException see) { catch (SpelException see) {
see.setPosition(getLeftOperand().getCharPositionInLine()); see.setPosition(getLeftOperand().getCharPositionInLine());
@ -56,7 +56,7 @@ public class OperatorOr extends Operator {
} }
try { try {
rightValue = state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR); rightValue = (Boolean)state.convertValue(getRightOperand().getValueInternal(state), BOOLEAN_TYPE_DESCRIPTOR);
} }
catch (SpelException see) { catch (SpelException see) {
see.setPosition(getRightOperand().getCharPositionInLine()); see.setPosition(getRightOperand().getCharPositionInLine());

View File

@ -86,7 +86,7 @@ public class StandardTypeConverter implements TypeConverter {
} }
@SuppressWarnings("unchecked") @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...) // For activation when conversion service available - this replaces the rest of the method (probably...)
// try { // try {
// return (T)conversionService.executeConversion(value, typeDescriptor); // return (T)conversionService.executeConversion(value, typeDescriptor);
@ -95,7 +95,7 @@ public class StandardTypeConverter implements TypeConverter {
// } catch (ConversionException ce) { // } catch (ConversionException ce) {
// throw new SpelException(ce, SpelMessages.TYPE_CONVERSION_ERROR, value.getClass(), typeDescriptor.asString()); // 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) { public boolean canConvert(Class<?> sourceType, Class<?> targetType) {

View File

@ -111,9 +111,9 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T convertValue(Object value, TypeDescriptor typeDescriptor) public Object convertValue(Object value, TypeDescriptor typeDescriptor)
throws EvaluationException { throws EvaluationException {
return (T)super.executeConversion(value, typeDescriptor); return super.executeConversion(value, typeDescriptor);
} }
} }

View File

@ -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);
}
}