[jboss-jira] [JBoss JIRA] Closed: (JBRULES-1460) MVEL parser uses wrong precedence for []
Mark Proctor (JIRA)
jira-events at lists.jboss.org
Wed Mar 12 12:16:58 EDT 2008
[ http://jira.jboss.com/jira/browse/JBRULES-1460?page=all ]
Mark Proctor closed JBRULES-1460.
---------------------------------
Resolution: Cannot Reproduce Bug
Assignee: Mark Proctor
I've been unable to reproduce this bug, maybe you are using an older version than 4.0.4? Anyway we have added your unit test to the 4.0.x branch and trunk. You can see those added tests in the svn commot tab for this JIRA, please review that we aren't mistaking what you are reporting. This is what the test currently looks like, please re-open if you think there is still a problem:
public void testMVELConsequenceWithMapsAndArrays() throws Exception {
String rule = "package org.test;\n";
rule += "import java.util.ArrayList\n";
rule += "import java.util.HashMap\n";
rule += "global java.util.List list\n";
rule += "rule \"Test Rule\"\n";
rule += " dialect \"mvel\"";
rule += "when\n";
rule += "then\n";
rule += " m = new HashMap();\n";
rule += " l = new ArrayList();\n";
rule += " l.add(\"first\");\n";
rule += " m.put(\"content\", l);\n";
rule += " System.out.println(m[\"content\"][0]);\n";
rule += " list.add(m[\"content\"][0]);\n";
rule += "end";
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( new StringReader( rule ));
final Package pkg = builder.getPackage();
final RuleBase ruleBase = getRuleBase();
ruleBase.addPackage(pkg);
final StatefulSession session = ruleBase.newStatefulSession();
List list = new ArrayList();
session.setGlobal( "list", list );
session.fireAllRules();
assertEquals( 1, list.size() );
assertEquals( "first", list.get( 0 ) );
}
> MVEL parser uses wrong precedence for []
> ----------------------------------------
>
> Key: JBRULES-1460
> URL: http://jira.jboss.com/jira/browse/JBRULES-1460
> Project: JBoss Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 4.0.4
> Reporter: Godmar Back
> Assigned To: Mark Proctor
>
> Consider this .drl file:
> --
> package test;
> import java.util.ArrayList;
> import java.util.HashMap;
> dialect "mvel"
> rule "Rule #1"
> when
> then
> m = new HashMap();
> l = new ArrayList();
> l.add("first");
> m.put("content", l);
> System.out.println(m["content"][0]);
> end
> ---
> which produces:
> org.mvel.PropertyAccessException: unable to resolve property: out.println(m["content"][0])
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:285)
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:107)
> at org.mvel.ast.LiteralDeepPropertyNode.getReducedValueAccelerated(LiteralDeepPropertyNode.java:26)
> at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
> at org.mvel.CompiledExpression.getValue(CompiledExpression.java:107)
> at org.mvel.MVEL.executeExpression(MVEL.java:223)
> at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
> at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
> at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
> at org.libx.autodetect.DroolsDriver$Host.fireAllRules(DroolsDriver.java:63)
> at org.libx.autodetect.DroolsDriver.main(DroolsDriver.java:135)
> Caused by: org.mvel.PropertyAccessException: unable to resolve property: unable to resolve method: java.io.PrintStream.println(java.util.ArrayList, org.mvel.util.FastList) [arglength=2]
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:558)
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:257)
> ... 12 more
> Exception in thread "main" org.drools.spi.ConsequenceException: org.mvel.PropertyAccessException: unable to resolve property: out.println(m["content"][0])
> at org.drools.base.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:14)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:554)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:514)
> at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:471)
> at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:433)
> at org.libx.autodetect.DroolsDriver$Host.fireAllRules(DroolsDriver.java:63)
> at org.libx.autodetect.DroolsDriver.main(DroolsDriver.java:135)
> Caused by: org.mvel.PropertyAccessException: unable to resolve property: out.println(m["content"][0])
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:285)
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:107)
> at org.mvel.ast.LiteralDeepPropertyNode.getReducedValueAccelerated(LiteralDeepPropertyNode.java:26)
> at org.mvel.MVELRuntime.execute(MVELRuntime.java:88)
> at org.mvel.CompiledExpression.getValue(CompiledExpression.java:107)
> at org.mvel.MVEL.executeExpression(MVEL.java:223)
> at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:47)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:550)
> ... 5 more
> Caused by: org.mvel.PropertyAccessException: unable to resolve property: unable to resolve method: java.io.PrintStream.println(java.util.ArrayList, org.mvel.util.FastList) [arglength=2]
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:558)
> at org.mvel.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:257)
> ... 12 more
> but changing:
> System.out.println(m["content"][0]);
> to
> System.out.println((m["content"])[0]);
> works. (So does assigning m["content"] to a temporary variable.)
> BTW: if you say that's a MVEL issue, not a Drools issue, consider that I have no other reason to use MVEL than to be able to use Drools. That's why I filed this bug here. I don't know how to run MVEL in any other environment, nor am I interested in it - I'd rather use a mature scripting language (beanshell comes to mind) that doesn't exhibit such basic bugs. Why don't you?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list