[
https://issues.apache.org/jira/browse/JEXL-154?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14566462#comment-14566462
]
Henri Biestro commented on JEXL-154:
------------------------------------
The issue does not occur on 3.0 trunk.
The following test passes.
{code}
public static class Utils {
public <T> List<T> asList(T[] array) {
return Arrays.asList(array);
}
public List<Integer> asList(int[] array) {
List<Integer> l = new ArrayList<>(array.length);
for(int i : array) {
l.add(i);
}
return l;
}
}
public void test148a() throws Exception {
JexlEngine jexl = new Engine();
JexlContext jc = new MapContext();
jc.set("u", new Utils());
String src = "u.asList(['foo', 'bar'])";
JexlScript e = jexl.createScript(src);
Object o = e.execute(jc);
Assert.assertTrue(o instanceof List);
Assert.assertEquals(Arrays.asList("foo", "bar"), o);
src = "u.asList([1, 2])";
e = jexl.createScript(src);
o = e.execute(jc);
Assert.assertTrue(o instanceof List);
Assert.assertEquals(Arrays.asList(1, 2), o);
}
{code}
> JEXL method lookup incorrectly interprets object array param as varargs
> -----------------------------------------------------------------------
>
> Key: JEXL-154
> URL: https://issues.apache.org/jira/browse/JEXL-154
> Project: Commons JEXL
> Issue Type: Bug
> Affects Versions: 2.1.1
> Reporter: David Loone
> Priority: Minor
>
> Say I have an object in my context with a method like:
> {code}
> public <T> List<T> asList(T[] array) {
> return Arrays.asList(array);
> }
> {code}
> When I call that from a JEXL expression with something like:
> {code}
> utils.asList(["foo", "bar"])
> {code}
> The JEXL method finder seems to treat the method like a varargs method, and
> puts the whole string array into the first element of the formal parameter,
> rather than mapping the string array onto the object array. That is, the
> method receives an array of length 1, with that first element being a string
> array of length 2.
> To illustrate further, the problem goes away if I change the method to look
> like:
> {code}
> public <T> List<T> asList(T[] array, String ... dummy) {
> return Arrays.asList(array);
> }
> {code}
> since this forces the T[] array to be interpreted correctly.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)