[rules-users] Slf4j Log4j logger not working with Drools drl while using as a global variable.

Wolfgang Laun wolfgang.laun at gmail.com
Tue May 27 04:08:24 EDT 2014


@Geoffrey: did you see the java.lang.ArrayIndexOutOfBoundsException?
Doesn't look like a null pointer causing an exception. The upstairs
exception might add the basic exceptions's message to its message.

@Soumya: Which Drools version are you using? Basically, this situation
is handled correctly by 5.4 and 5.5.

-W

On 27/05/2014, Geoffrey De Smet <ge0ffrey.spam at gmail.com> wrote:
> Check if the logger isn't null (by adding a System.out in the then part
> of the rule).
>
> If that's the case, then that error message is pretty poor (or even
> incorrect):
>     java.lang.RuntimeException: cannot invoke method: info
> It should clearly talk about a NullPointer instead.
> So, if that's the case, create a jira issue.
>    https://issues.jboss.org/browse/DROOLS
>
>
> On 27-05-14 07:09, Soumya.plavaga wrote:
>> I am using global slf4j log4j logger as a global variable within our drl
>> and
>> inserting that global logger value at runtime into kiesession. While we
>> are
>> trying to do logger.info with multiple arguments then it's giving the
>> following exception stack trace -
>>
>> Exception executing consequence for rule "Test Logger 2" in
>> test.rules.system: java.lang.RuntimeException: cannot invoke method: info
>> 	at
>> org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
>> 	at
>> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1027)
>> 	at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:129)
>> 	at
>> org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:71)
>> 	at
>> org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:935)
>> 	at
>> org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1200)
>> 	at
>> org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:952)
>> 	at
>> org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:926)
>> 	at
>> org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:232)
>> 	at
>> test.platform.rules.executor.service.impl.RuleExecutorServiceImplTest.testExecuteRule(RuleExecutorServiceImplTest.java:230)
>> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> 	at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>> 	at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> 	at java.lang.reflect.Method.invoke(Method.java:606)
>> 	at
>> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
>> 	at
>> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>> 	at
>> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
>> 	at
>> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>> 	at
>> org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
>> 	at
>> org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
>> 	at
>> org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
>> 	at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
>> 	at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
>> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
>> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
>> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
>> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
>> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
>> 	at
>> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
>> 	at
>> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
>> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
>> 	at
>> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
>> 	at
>> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>> 	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: java.lang.RuntimeException: cannot invoke method: info
>> 	at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
>> 	at
>> org.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
>> 	at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
>> 	at org.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
>> 	at
>> org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
>> 	at
>> org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
>> 	at org.mvel2.MVEL.executeExpression(MVEL.java:930)
>> 	at
>> org.drools.core.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:107)
>> 	at
>> org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1016)
>> 	... 36 more
>> Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
>> 	at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:140)
>> 	at
>> org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
>> 	... 44 more
>>
>>
>> Example: My drl file looks like this -
>>
>> package test.system.rule;
>>
>> import test.platform.model.*;
>> import org.slf4j.Logger;
>>
>> global Logger logger;
>>
>> rule "Test Logger 1"
>>
>> when
>>
>> then
>>
>> logger.info("within test logger 1");
>>
>> end
>>
>> rule "Test Logger 2"
>>
>> when
>>
>> then
>>
>> logger.info("within test logger 2. Rule fired {}",
>> drools.getRule().getName());
>>
>> end
>>
>>
>> While rules are firing then the first logger is getting printed into
>> console
>> but second one is not getting printed and giving the above exception to
>> me.
>>
>>
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/Slf4j-Log4j-logger-not-working-with-Drools-drl-while-using-as-a-global-variable-tp4029707.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>


More information about the rules-users mailing list