Author: markt Date: Fri Dec 5 17:32:34 2014 New Revision: 1643365 URL: http://svn.apache.org/r1643365 Log: Part 1 of fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=57309 Addressed the direct calls to ELSupport.coerceToType() Still need to address the type specific versions of that method.
Modified: tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java tomcat/trunk/java/org/apache/el/lang/ELSupport.java tomcat/trunk/java/org/apache/el/parser/AstFunction.java tomcat/trunk/java/org/apache/el/parser/AstValue.java tomcat/trunk/java/org/apache/el/util/ReflectionUtil.java tomcat/trunk/test/org/apache/el/lang/TestELSupport.java tomcat/trunk/test/org/apache/el/util/TestReflectionUtil.java Modified: tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java (original) +++ tomcat/trunk/java/org/apache/el/ExpressionFactoryImpl.java Fri Dec 5 17:32:34 2014 @@ -44,7 +44,7 @@ public class ExpressionFactoryImpl exten @Override public Object coerceToType(Object obj, Class<?> type) { - return ELSupport.coerceToType(obj, type); + return ELSupport.coerceToType(null, obj, type); } @Override Modified: tomcat/trunk/java/org/apache/el/lang/ELSupport.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/lang/ELSupport.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/lang/ELSupport.java (original) +++ tomcat/trunk/java/org/apache/el/lang/ELSupport.java Fri Dec 5 17:32:34 2014 @@ -28,8 +28,8 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import javax.el.ELContext; import javax.el.ELException; - import org.apache.el.util.MessageFactory; @@ -430,9 +430,21 @@ public class ELSupport { } } - public static final Object coerceToType(final Object obj, + public static final Object coerceToType(final ELContext ctx, final Object obj, final Class<?> type) throws ELException { + if (ctx != null) { + boolean originalIsPropertyResolved = ctx.isPropertyResolved(); + try { + Object result = ctx.getELResolver().convertToType(ctx, obj, type); + if (ctx.isPropertyResolved()) { + return result; + } + } finally { + ctx.setPropertyResolved(originalIsPropertyResolved); + } + } + if (type == null || Object.class.equals(type) || (obj != null && type.isAssignableFrom(obj.getClass()))) { return obj; @@ -495,14 +507,14 @@ public class ELSupport { // Handle arrays if (type.isArray() && obj.getClass().isArray()) { - return coerceToArray(obj, type); + return coerceToArray(ctx, obj, type); } throw new ELException(MessageFactory.get("error.convert", obj, obj.getClass(), type)); } - private static Object coerceToArray(final Object obj, + private static Object coerceToArray(final ELContext ctx, final Object obj, final Class<?> type) { // Note: Nested arrays will result in nested calls to this method. @@ -517,7 +529,7 @@ public class ELSupport { Object result = Array.newInstance(componentType, size); // Coerce each element in turn. for (int i = 0; i < size; i++) { - Array.set(result, i, coerceToType(Array.get(obj, i), componentType)); + Array.set(result, i, coerceToType(ctx, Array.get(obj, i), componentType)); } return result; Modified: tomcat/trunk/java/org/apache/el/parser/AstFunction.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstFunction.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/parser/AstFunction.java (original) +++ tomcat/trunk/java/org/apache/el/parser/AstFunction.java Fri Dec 5 17:32:34 2014 @@ -176,12 +176,12 @@ public final class AstFunction extends S Class<?> target = paramTypes[i].getComponentType(); for (int j = i; j < inputParameterCount; j++) { varargs[j-i] = parameters.jjtGetChild(j).getValue(ctx); - varargs[j-i] = coerceToType(varargs[j-i], target); + varargs[j-i] = coerceToType(ctx, varargs[j-i], target); } } } else { params[i] = parameters.jjtGetChild(i).getValue(ctx); - params[i] = coerceToType(params[i], paramTypes[i]); + params[i] = coerceToType(ctx, params[i], paramTypes[i]); } } } catch (ELException ele) { Modified: tomcat/trunk/java/org/apache/el/parser/AstValue.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/parser/AstValue.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/parser/AstValue.java (original) +++ tomcat/trunk/java/org/apache/el/parser/AstValue.java Fri Dec 5 17:32:34 2014 @@ -198,7 +198,7 @@ public final class AstValue extends Simp // coerce to the expected type Class<?> targetClass = resolver.getType(ctx, t.base, t.property); resolver.setValue(ctx, t.base, t.property, - ELSupport.coerceToType(value, targetClass)); + ELSupport.coerceToType(ctx, value, targetClass)); if (!ctx.isPropertyResolved()) { throw new PropertyNotFoundException(MessageFactory.get( "error.resolver.unhandled", t.base, t.property)); @@ -212,7 +212,7 @@ public final class AstValue extends Simp throws ELException { Target t = getTarget(ctx); Method m = ReflectionUtil.getMethod( - t.base, t.property, paramTypes, null); + ctx, t.base, t.property, paramTypes, null); return new MethodInfo(m.getName(), m.getReturnType(), m .getParameterTypes()); } @@ -235,10 +235,10 @@ public final class AstValue extends Simp values = paramValues; types = paramTypes; } - m = ReflectionUtil.getMethod(t.base, t.property, types, values); + m = ReflectionUtil.getMethod(ctx, t.base, t.property, types, values); // Handle varArgs and any co-ercion required - values = convertArgs(values, m); + values = convertArgs(ctx, values, m); Object result = null; try { @@ -260,7 +260,7 @@ public final class AstValue extends Simp return result; } - private Object[] convertArgs(Object[] src, Method m) { + private Object[] convertArgs(EvaluationContext ctx, Object[] src, Method m) { Class<?>[] types = m.getParameterTypes(); if (types.length == 0) { return new Object[0]; @@ -271,7 +271,7 @@ public final class AstValue extends Simp Object[] dest = new Object[paramCount]; for (int i = 0; i < paramCount - 1; i++) { - dest[i] = ELSupport.coerceToType(src[i], types[i]); + dest[i] = ELSupport.coerceToType(ctx, src[i], types[i]); } if (m.isVarArgs()) { @@ -279,13 +279,13 @@ public final class AstValue extends Simp m.getParameterTypes()[paramCount - 1].getComponentType(), src.length - (paramCount - 1)); for (int i = 0; i < src.length - (paramCount - 1); i ++) { - varArgs[i] = ELSupport.coerceToType(src[paramCount - 1 + i], + varArgs[i] = ELSupport.coerceToType(ctx, src[paramCount - 1 + i], types[paramCount - 1].getComponentType()); } dest[paramCount - 1] = varArgs; } else { dest[paramCount - 1] = ELSupport.coerceToType( - src[paramCount - 1], types[paramCount - 1]); + ctx, src[paramCount - 1], types[paramCount - 1]); } return dest; Modified: tomcat/trunk/java/org/apache/el/util/ReflectionUtil.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/el/util/ReflectionUtil.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/el/util/ReflectionUtil.java (original) +++ tomcat/trunk/java/org/apache/el/util/ReflectionUtil.java Fri Dec 5 17:32:34 2014 @@ -28,6 +28,7 @@ import javax.el.ELException; import javax.el.MethodNotFoundException; import org.apache.el.lang.ELSupport; +import org.apache.el.lang.EvaluationContext; /** @@ -111,6 +112,7 @@ public class ReflectionUtil { /** * Returns a method based on the criteria. + * @param ctx the context in which the expression is being evaluated * @param base the object that owns the method * @param property the name of the method * @param paramTypes the parameter types to use @@ -124,7 +126,7 @@ public class ReflectionUtil { * the code in sync. */ @SuppressWarnings("null") - public static Method getMethod(Object base, Object property, + public static Method getMethod(EvaluationContext ctx, Object base, Object property, Class<?>[] paramTypes, Object[] paramValues) throws MethodNotFoundException { if (base == null || property == null) { @@ -186,7 +188,7 @@ public class ReflectionUtil { noMatch = true; break; } else { - if (isCoercibleFrom(paramValues[j], varType)) { + if (isCoercibleFrom(ctx, paramValues[j], varType)) { coercibleMatch++; } else { noMatch = true; @@ -205,7 +207,7 @@ public class ReflectionUtil { noMatch = true; break; } else { - if (isCoercibleFrom(paramValues[i], mParamTypes[i])) { + if (isCoercibleFrom(ctx, paramValues[i], mParamTypes[i])) { coercibleMatch++; } else { noMatch = true; @@ -381,11 +383,11 @@ public class ReflectionUtil { * This class duplicates code in javax.el.Util. When making changes keep * the code in sync. */ - private static boolean isCoercibleFrom(Object src, Class<?> target) { + private static boolean isCoercibleFrom(EvaluationContext ctx, Object src, Class<?> target) { // TODO: This isn't pretty but it works. Significant refactoring would // be required to avoid the exception. try { - ELSupport.coerceToType(src, target); + ELSupport.coerceToType(ctx, src, target); } catch (ELException e) { return false; } Modified: tomcat/trunk/test/org/apache/el/lang/TestELSupport.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/lang/TestELSupport.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/el/lang/TestELSupport.java (original) +++ tomcat/trunk/test/org/apache/el/lang/TestELSupport.java Fri Dec 5 17:32:34 2014 @@ -81,13 +81,13 @@ public class TestELSupport { @Test public void testCoerceIntegerToNumber() { Integer input = Integer.valueOf(4390241); - Object output = ELSupport.coerceToType(input, Number.class); + Object output = ELSupport.coerceToType(null, input, Number.class); assertEquals(input, output); } @Test public void testCoerceNullToNumber() { - Object output = ELSupport.coerceToType(null, Number.class); + Object output = ELSupport.coerceToType(null, null, Number.class); assertNull(output); } Modified: tomcat/trunk/test/org/apache/el/util/TestReflectionUtil.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/el/util/TestReflectionUtil.java?rev=1643365&r1=1643364&r2=1643365&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/el/util/TestReflectionUtil.java (original) +++ tomcat/trunk/test/org/apache/el/util/TestReflectionUtil.java Fri Dec 5 17:32:34 2014 @@ -30,7 +30,7 @@ public class TestReflectionUtil { */ @Test(expected=MethodNotFoundException.class) public void testBug54370a() { - ReflectionUtil.getMethod(BASE, "testA", + ReflectionUtil.getMethod(null, BASE, "testA", new Class[] {null, String.class}, new Object[] {null, ""}); } @@ -42,21 +42,21 @@ public class TestReflectionUtil { */ @Test(expected=MethodNotFoundException.class) public void testBug54370b() { - ReflectionUtil.getMethod(BASE, "testB", + ReflectionUtil.getMethod(null, BASE, "testB", new Class[] {null, String.class}, new Object[] {null, ""}); } @Test public void testBug54370c() { - ReflectionUtil.getMethod(BASE, "testC", + ReflectionUtil.getMethod(null, BASE, "testC", new Class[] {null}, new Object[] {null}); } @Test public void testBug54370d() { - ReflectionUtil.getMethod(BASE, "testD", + ReflectionUtil.getMethod(null, BASE, "testD", new Class[] {null}, new Object[] {null}); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org