[jboss-jira] [JBoss JIRA] Commented: (JBRULES-2481) Unable to reference globals in object constructors on RHS of rule

Chris DeLashmutt (JIRA) jira-events at lists.jboss.org
Tue May 18 09:47:06 EDT 2010


    [ https://jira.jboss.org/browse/JBRULES-2481?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12531230#action_12531230 ] 

Chris DeLashmutt commented on JBRULES-2481:
-------------------------------------------

This no longer seems to be an issue in trunk.

> Unable to reference globals in object constructors on RHS of rule
> -----------------------------------------------------------------
>
>                 Key: JBRULES-2481
>                 URL: https://jira.jboss.org/browse/JBRULES-2481
>             Project: Drools
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>          Components: drools-core  (expert)
>    Affects Versions: 5.0.1.FINAL, 5.1.0.M1
>         Environment: Windows 7, Sun JDK 1.6.0_17
>            Reporter: Chris DeLashmutt
>            Assignee: Mark Proctor
>             Fix For: 5.1.0.M2
>
>         Attachments: drools-constructor-global-fail.zip
>
>
> After migrating to Drools 5 from 4.0.7, it seems that you can't reference globals in object constructors on the RHS of a rule.  Here is my DRL:
> package test.rules
> #list any import classes here.
> import test.domain.Field;
> #declare any global variables here
> global test.service.CalendarManager calendarManager;
> dialect "mvel"
> rule "FieldRuleTest.todayField"
>     when
>     then
>         new Field("todayField",calendarManager.getToday())
> end
> After reading this DRL with PackageBuilder, creating a StatefulSession from the resulting rulebase, setting the global, and then executing fireAllRules, I get the following exception:
> org.drools.runtime.rule.ConsequenceException: [Error: unable to access property (null parent): calendarManager]
> [Near : {... Unknown ....}]
>              ^
> [Line: 1, Column: 0]
> 	at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:980)
> 	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:917)
> 	at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1126)
> 	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:697)
> 	at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:663)
> 	at test.MvelBindingProblemTest.mvelBindingTestFailure(MvelBindingProblemTest.java:40)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> 	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> 	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> 	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: [Error: unable to access property (null parent): calendarManager]
> [Near : {... Unknown ....}]
>              ^
> [Line: 1, Column: 0]
> 	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:860)
> 	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getBeanProperty(ReflectiveAccessorOptimizer.java:584)
> 	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:312)
> 	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:138)
> 	at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:133)
> 	at org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:41)
> 	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileConstructor(ReflectiveAccessorOptimizer.java:1090)
> 	at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeObjectCreation(ReflectiveAccessorOptimizer.java:1047)
> 	at org.mvel2.ast.NewObjectNode.getReducedValueAccelerated(NewObjectNode.java:158)
> 	at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
> 	at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:104)
> 	at org.mvel2.MVEL.executeExpression(MVEL.java:995)
> 	at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:87)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:971)
> 	... 27 more
> Attached is a project with a failing test case for this issue.
> If I simply add a silly reference to the global to the DRL as follows, everything works:
> rule "FieldRuleTest.todayField"
>     when
>     then
>         stupidLocalVariable = calendarManager
>         new Field("todayField",calendarManager.getToday())
> end

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the jboss-jira mailing list