Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0.9, 2.0.10, 2.0.11
-
Fix Version/s: 2.0.12
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
REPORTED BY DAMON:
*******************************************
Hi,
I'm having trouble using MVEL syntax in Drools with arrays of custom
classes. e.g. in the following example, it gets as far as 12 OK, but
13 fails with an exception.
rule "test java"
salience 2
dialect "java"
then
test(1, new String[]
test(2, new String[]{new String("a"), new String("b")});
test(3, new Foo[]{new Foo("a"), new Foo("b")});
end
rule "test mvel"
salience 1
dialect "mvel"
then
test(11, {"a", "b"}
);
test(12,
test(13, {new Foo("a"), new Foo("b")});
end
function void test(int id, Object[] o) {
System.out.println(id + " " + o.length);
}
Foo is just a dummy class. It doesn't make any difference if the
constructor has no arguments.
Any ideas as to what I am doing wrong? The MVEL documentation
indicates that this sort of thing should work. Is it a limitation of
Drools?
I want to use the MVEL syntax rather than Java syntax because my rule
has other lines in it that are also using MVEL and if I redo the whole
rule using Java syntax then it doesn't read as nicely.
Thanks, Damon
************************************
Mike, I added 2 tests to the mvel CoreConfidenceTests showing the problem:
public void testArray() {
String ex = " TestHelper.method(1, new String[]{\"a\", \"b\"});\n" +
" TestHelper.method(2, new String[]{new String("a"), new String("b")}
);\n"+
" TestHelper.method(3, new Foo[]
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport( TestHelper.class );
ctx.addImport( Foo.class );
ExpressionCompiler compiler = new ExpressionCompiler(ex);
CompiledExpression expr = compiler.compile(ctx);
MVEL.executeExpression( expr );
}
public void testArray2() {
String ex = " TestHelper.method(1, {\"a\", \"b\"});\n" +
" TestHelper.method(2, {new String(\"a\"), new String(\"b\")});\n"+
" TestHelper.method(3, {new Foo("a"), new Foo("b")}
);";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addImport( TestHelper.class );
ctx.addImport( Foo.class );
ExpressionCompiler compiler = new ExpressionCompiler(ex);
CompiledExpression expr = compiler.compile(ctx);
MVEL.executeExpression( expr );
}
fixed in trunk