From f899a72e1c6ecd2830c9221fde63d4eee3cbb69a Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Thu, 9 Apr 2009 16:00:53 +0000 Subject: [PATCH] Changed signature of convertValue() to keep the Sun compiler happy git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@960 50f2f4bb-b051-0410-bef5-90022cba6387 --- .../expression/TypeConverter.java | 2 +- .../expression/spel/ExpressionState.java | 4 +-- .../spel/ast/ConstructorReference.java | 2 +- .../expression/spel/ast/Indexer.java | 22 +++++++------- .../expression/spel/ast/OperatorAnd.java | 4 +-- .../expression/spel/ast/OperatorNot.java | 2 +- .../expression/spel/ast/OperatorOr.java | 6 ++-- .../spel/support/StandardTypeConverter.java | 4 +-- ...essionTestsUsingCoreConversionService.java | 4 +-- .../expression/spel/SpringEL300Tests.java | 30 +++++++++++++++++++ 10 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java b/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java index ce3b3bedeec..e4422dd29db 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/TypeConverter.java @@ -48,7 +48,7 @@ public interface TypeConverter { * @return the converted value * @throws EvaluationException if conversion is not possible */ - 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. diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java index 18f4e3f3b78..75a26674bb9 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ExpressionState.java @@ -100,11 +100,11 @@ public class ExpressionState { return this.relatedContext.getTypeLocator().findType(type); } - public 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 convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { + public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { return this.relatedContext.getTypeConverter().convertValue(value.getValue(), targetTypeDescriptor); } diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java index 06d690cddb5..aae9ebcbc12 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/ConstructorReference.java @@ -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; diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index e6c8a2662e0..76e329555c2 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -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); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorAnd.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorAnd.java index 5ee84123724..8a4d048bf3e 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorAnd.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorAnd.java @@ -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()); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorNot.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorNot.java index 574713b3e92..771e681acbd 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorNot.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorNot.java @@ -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) { diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorOr.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorOr.java index 6c56adf337b..8087c80d080 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorOr.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/ast/OperatorOr.java @@ -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()); diff --git a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java index e6baf7d0439..b48dfcc23d1 100644 --- a/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java +++ b/org.springframework.expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java @@ -86,7 +86,7 @@ public class StandardTypeConverter implements TypeConverter { } @SuppressWarnings("unchecked") - public 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) { diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java index 96d4356419d..2215acb3a4f 100644 --- a/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/ExpressionTestsUsingCoreConversionService.java @@ -111,9 +111,9 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas } @SuppressWarnings("unchecked") - public 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); } } diff --git a/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java b/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java new file mode 100644 index 00000000000..e7275e22995 --- /dev/null +++ b/org.springframework.expression/src/test/java/org/springframework/expression/spel/SpringEL300Tests.java @@ -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); + } + +}