View | Details | Raw Unified | Return to bug 60431
Collapse All | Expand All

(-)java/org/apache/el/lang/ELSupport.java (+6 lines)
Lines 24-29 Link Here
24
import java.security.AccessController;
24
import java.security.AccessController;
25
import java.security.PrivilegedAction;
25
import java.security.PrivilegedAction;
26
import java.util.Collections;
26
import java.util.Collections;
27
import java.util.List;
27
import java.util.Map;
28
import java.util.Map;
28
import java.util.Set;
29
import java.util.Set;
29
30
Lines 577-582 Link Here
577
        if (type.isArray() && obj.getClass().isArray()) {
578
        if (type.isArray() && obj.getClass().isArray()) {
578
            return coerceToArray(ctx, obj, type);
579
            return coerceToArray(ctx, obj, type);
579
        }
580
        }
581
        
582
        // Handle lists
583
        if (type.isArray() && List.class.isInstance(obj)) {
584
            return coerceToArray(ctx, ((List)obj).toArray(), type);
585
        }
580
586
581
        throw new ELException(MessageFactory.get("error.convert",
587
        throw new ELException(MessageFactory.get("error.convert",
582
                obj, obj.getClass(), type));
588
                obj, obj.getClass(), type));
(-)java/org/apache/el/parser/AstFunction.java (+3 lines)
Lines 170-175 Link Here
170
                    if (m.isVarArgs() && i == methodParameterCount - 1) {
170
                    if (m.isVarArgs() && i == methodParameterCount - 1) {
171
                        if (inputParameterCount < methodParameterCount) {
171
                        if (inputParameterCount < methodParameterCount) {
172
                            params[i] = null;
172
                            params[i] = null;
173
                        } else if (inputParameterCount == methodParameterCount && paramTypes[i].isArray()) {
174
                        	params[i] = parameters.jjtGetChild(i).getValue(ctx);
175
                            params[i] = coerceToType(ctx, params[i], paramTypes[i]);
173
                        } else {
176
                        } else {
174
                            Object[] varargs =
177
                            Object[] varargs =
175
                                    new Object[inputParameterCount - methodParameterCount + 1];
178
                                    new Object[inputParameterCount - methodParameterCount + 1];
(-)test/org/apache/el/parser/TestAstFunction.java (+27 lines)
Lines 38-41 Link Here
38
        Object result = processor.getValue("valueOf(1000)", Integer.class);
38
        Object result = processor.getValue("valueOf(1000)", Integer.class);
39
        Assert.assertEquals(Integer.valueOf(1000), result);
39
        Assert.assertEquals(Integer.valueOf(1000), result);
40
    }
40
    }
41
    
42
    @Test
43
    public void testParamsToVararg() throws Exception {
44
        ELProcessor processor = new ELProcessor();
45
        processor.getELManager().mapFunction("fn", "echo", TesterUtilA.class.getMethod("echo", String[].class));
46
        Object result = processor.getValue("fn:echo('a', 'b', 'c')", String.class);
47
        Assert.assertEquals("a, b, c", result);
48
    }
49
    
50
    @Test
51
    public void testArrayToVararg() throws Exception {
52
        ELProcessor processor = new ELProcessor();
53
        processor.getELManager().getELContext().getImportHandler()
54
        .importStatic("org.apache.el.parser.TesterUtilA.toArray");
55
        processor.getELManager().mapFunction("fn", "echo", TesterUtilA.class.getMethod("echo", String[].class));
56
        Object result = processor.getValue("fn:echo(toArray('a', 'b'))", String.class);
57
        Assert.assertEquals("a, b", result);
58
    }
59
    
60
    @Test
61
    public void testListToVararg() throws Exception {
62
        ELProcessor processor = new ELProcessor();
63
        processor.getELManager().mapFunction("fn", "echo", TesterUtilA.class.getMethod("echo", String[].class));
64
        Object result = processor.getValue("fn:echo(['a', 'b'])", String.class);
65
        Assert.assertEquals("a, b", result);
66
    }
67
    
41
}
68
}
(-)test/org/apache/el/parser/TesterUtilA.java (+24 lines)
Line 0 Link Here
1
package org.apache.el.parser;
2
3
public class TesterUtilA {
4
5
    public static String echo(String...strings) {
6
        if (strings == null) {
7
            return null;
8
        }
9
10
        StringBuilder sb = new StringBuilder();
11
        for (int i = 0; i < strings.length; i++) {
12
            if (i > 0) {
13
                sb.append(", ");
14
            }
15
            sb.append(strings[i]);
16
        }
17
        return sb.toString();
18
    }
19
20
    public static String[] toArray(String arg1, String arg2) {
21
        return new String[] {arg1, arg2};
22
    }
23
	
24
}

Return to bug 60431