Author: markt
Date: Wed Oct 29 09:49:02 2014
New Revision: 1635081
URL: http://svn.apache.org/r1635081
Log:
When coercing an object to an array type in Expression Langauage, handle the
case where the source object is an array of primitives.
Modified:
tomcat/trunk/java/org/apache/el/lang/ELSupport.java
tomcat/trunk/test/javax/el/TestELProcessor.java
tomcat/trunk/test/javax/el/TesterBean.java
tomcat/trunk/webapps/docs/changelog.xml
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=1635081&r1=1635080&r2=1635081&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/el/lang/ELSupport.java (original)
+++ tomcat/trunk/java/org/apache/el/lang/ELSupport.java Wed Oct 29 09:49:02 2014
@@ -494,16 +494,18 @@ public class ELSupport {
final Class<?> type) {
// Note: Nested arrays will result in nested calls to this method.
+ // Note: Calling method has checked the obj is an array.
+
+ int size = Array.getLength(obj);
// Cast the input object to an array (calling method has checked it is
// an array)
- Object[] array = (Object[]) obj;
// Get the target type for the array elements
Class<?> componentType = type.getComponentType();
// Create a new array of the correct type
- Object result = Array.newInstance(componentType, array.length);
+ Object result = Array.newInstance(componentType, size);
// Coerce each element in turn.
- for (int i = 0; i < array.length; i++) {
- Array.set(result, i, coerceToType(array[i], componentType));
+ for (int i = 0; i < size; i++) {
+ Array.set(result, i, coerceToType(Array.get(obj, i),
componentType));
}
return result;
Modified: tomcat/trunk/test/javax/el/TestELProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TestELProcessor.java?rev=1635081&r1=1635080&r2=1635081&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TestELProcessor.java (original)
+++ tomcat/trunk/test/javax/el/TestELProcessor.java Wed Oct 29 09:49:02 2014
@@ -191,4 +191,21 @@ public class TestELProcessor {
elp.eval("fn:test(null, null)");
Assert.assertEquals("I", TesterFunctions.getCallList());
}
+
+
+ @Test
+ public void testPrimitiveArray01() {
+ ELProcessor elp = new ELProcessor();
+ TesterBean bean01= new TesterBean("bean01");
+ elp.defineBean("bean01", bean01);
+ elp.defineBean("bean02", new TesterBean("bean02"));
+
+ Object result =
elp.eval("bean02.setValueC(bean01.valueB);bean02.valueC");
+
+ Integer[] resultArray = (Integer[]) result;
+ Assert.assertEquals(bean01.getValueB().length, resultArray.length);
+ for (int i = 0; i < resultArray.length; i++) {
+ Assert.assertEquals(bean01.getValueB()[i],
resultArray[i].intValue());
+ }
+ }
}
Modified: tomcat/trunk/test/javax/el/TesterBean.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TesterBean.java?rev=1635081&r1=1635080&r2=1635081&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TesterBean.java (original)
+++ tomcat/trunk/test/javax/el/TesterBean.java Wed Oct 29 09:49:02 2014
@@ -19,6 +19,7 @@ package javax.el;
public class TesterBean {
private String name;
+ private Integer[] valueC;
public TesterBean(String name) {
this.name = name;
@@ -40,4 +41,16 @@ public class TesterBean {
public String getValueA() throws Exception {
throw new Exception();
}
+
+ public int[] getValueB() {
+ return new int[] {1,2,3,4,5};
+ }
+
+ public void setValueC(Integer[] values) {
+ valueC = values;
+ }
+
+ public Integer[] getValueC() {
+ return valueC;
+ }
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1635081&r1=1635080&r2=1635081&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Oct 29 09:49:02 2014
@@ -241,6 +241,11 @@
<code>$</code> and <code>#</code> when processing literal expressions
in
expression language. (markt)
</fix>
+ <fix>
+ When coercing an object to an array type in Expression Langauage,
handle
+ the case where the source object is an array of primitives.
+ (markt/kkolinko)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]