Quantcast

How handle exception thrown while looping in DRL file

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How handle exception thrown while looping in DRL file

ashwindrool
Hi,

I ran enhanced for loop in .DRL file .Its looping perfectly but after completion of loop its throwing error mentioned as follows:


org.drools.runtime.rule.ConsequenceException: rule: Test Maadiiiiiiiiiiiiiiiii

        at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
        at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
        at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
        at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
        at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:737)
        at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:701)
        at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
        at com.sample.DroolsTest.main(DroolsTest.java:156)
Caused by: java.lang.NullPointerException
        at com.sample.Rule_Test_Maadiiiiiiiiiiiiiiiii_0.defaultConsequence(Rule_Test_Maadiiiiiiiiiiiiiiiii_0.java:7)
        at com.sample.Rule_Test_Maadiiiiiiiiiiiiiiiii_0DefaultConsequenceInvoker.evaluate(Rule_Test_Maadiiiiiiiiiiiiiiiii_0DefaultConsequenceInvoker.java:27)
        at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
        ... 6 more
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

laune
Thanks for telling us.
-W


On 17/07/2012, ashwindrool <[hidden email]> wrote:

> Hi,
>
> I ran enhanced for loop in .DRL file .Its looping perfectly but after
> completion of loop its throwing error mentioned as follows:
>
>
> *org.drools.runtime.rule.ConsequenceException: rule: Test
> Maadiiiiiiiiiiiiiiiii
>
> at
> org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
> at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:737)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:701)
> at
> org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
> at com.sample.DroolsTest.main(DroolsTest.java:156)
> Caused by: java.lang.NullPointerException
> at
> com.sample.Rule_Test_Maadiiiiiiiiiiiiiiiii_0.defaultConsequence(Rule_Test_Maadiiiiiiiiiiiiiiiii_0.java:7)
> at
> com.sample.Rule_Test_Maadiiiiiiiiiiiiiiiii_0DefaultConsequenceInvoker.evaluate(Rule_Test_Maadiiiiiiiiiiiiiiiii_0DefaultConsequenceInvoker.java:27)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
> ... 6 more
> *
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

ashwindrool
Thnks for Replying ,

Plz give some idea in above issue.  
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

manstis
You haven't asked any questions, merely stated you have an error message.

Try posting some supporting code (DRL, related Java etc) it might help people.

On 17 July 2012 10:03, ashwindrool <[hidden email]> wrote:
Thnks for Replying ,

Plz give some idea in above issue.

--
View this message in context: http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727p4018730.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

ashwindrool
Sorry Mike,Laune


I am handling 100thousand records for that i am using CSV file and converting those records into objects which i am using for further calculation.

According to my requirement i have loop array inside DRL file

So i wrote following code in .java
 agCsv.setPolCounterList(polCounterList);
 agCsv.setAgentList(agentListArray);
 
     // local block end for policy---------------------------------------
     //firing  all rules from here-------------
           ksession.fireAllRules();
        //after firing rules destroying session object
           ksession.dispose();
         


after this  i am executing following rule DRL file

rule "Loop Test"
    salience 50
        when
       
        $a:AgentCSVBean()
       
       
        then
         
          for(Integer agentList: $a.getAgentList()) {
           
           System.out.println("--sam====="+agentList);
       
      }
   
   
               
end


Now above loop execute absolutely well but after finishing loop it throws Error




 




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

manstis
When you say the loop works fine, do the System.out's print what you expect?

On 17 July 2012 10:34, ashwindrool <[hidden email]> wrote:
Sorry Mike,Laune


I am handling 100thousand records for that i am using CSV file and
converting those records into objects which i am using for further
calculation.

According to my requirement i have loop array inside DRL file

So i wrote following code in .java
* agCsv.setPolCounterList(polCounterList);
 agCsv.setAgentList(agentListArray);

                  // local block end for policy---------------------------------------
                  //firing  all rules from here-------------
                        ksession.fireAllRules();
                     //after firing rules destroying session object
                        ksession.dispose();
                        *

after this  i am executing following rule DRL file

*rule "Loop Test"
    salience 50
        when

        $a:AgentCSVBean()


        then

          for(Integer agentList: $a.getAgentList()) {

           System.out.println("--sam====="+agentList);

      }



end*

Now above loop execute absolutely well but after finishing loop it throws
Error











--
View this message in context: http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727p4018732.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users


_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

ashwindrool
In reply to this post by manstis
Yes Mike,

I am getting expected output but after completion of loop it throws error
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

laune
Add an if statement testing for a List element being null, e.g.,

   for( Integer agentList: $a.getAgentList()) {
        if( agentList != null ){
           System.out.println("--sam====="+agentList);
       } else {
          System.out.println( "null element in list" );
      }
    }

-W


On 17/07/2012, ashwindrool <[hidden email]> wrote:

> Yes Mike,
>
> I am getting expected output but after completion of loop it throws error
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727p4018733.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

ashwindrool
Thnks Laune for ur reply but i tried that condition part even than also its coming up with same error
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

laune
Add println() before and after the for(){...} statement. What is the output?

How many AgentCSVBean() are inserted?
Could one of these have a field agentLsit that is null?

-W

On 17/07/2012, ashwindrool <[hidden email]> wrote:

> Thnks Laune for ur reply but i tried that condition part even than also its
> coming up with same error
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727p4018736.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

ashwindrool
Hi Laune,


I do wht u asked me, I added print statement before and after for loop


       
          System.out.println("Before");
          for(Integer agentList: $a.getAgentList()) {
          System.out.println("-==========-");
             if($a.getAgentList() != null ){
  System.out.println("--sam====="+agentList);
     }
     else{
     System.out.println("null");
     }
    }
     System.out.println("after");

   
   "Before" is getting printed twice and "After" only once.Then it prints Error message which i mentioned in catch block from where i called rule in java.

   in following order message getting printed
    before
   list of data
   after
   before
   error


im printing 128thousand records

No their is no null field in given records...................  

               
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

laune
On 17/07/2012, ashwindrool <[hidden email]> wrote:
> Hi Laune,
>
>
> I do wht u asked me, I added print statement before and after for loop
>
>
>
>    "Before" is getting printed twice and "After" only once.

Like this????
Before
Before
After
---Error message---

Please be more specific.

Add another if statement before the for statement testing whether
 if(  $a.getAgentList() == null ){
     System.out.println( "List is null" );
}


Then it prints

> Error message which i mentioned in catch block from where i called rule in
> java.
>
>    in following order message getting printed
>    * before
>    list of data
>    after
>    before
>    error*
>
> /im printing 128thousand records/
> *
> No their is no null field in given records...................
> *
>
>
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727p4018738.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

ashwindrool
In reply to this post by laune
HI Laune ,

I did required changes in code by adding if condition before for loop

System.out.println("Before");
           if($a.getAgentList() != null ){
  System.out.println("--sameeeeeeeeee=====");
     }
          for(Integer agentList: $a.getAgentList()) {
          System.out.println("-==========-");
             if($a.getAgentList() != null ){
  System.out.println("--sam====="+agentList);
     }
     else{
     System.out.println("null");
     }
    }
     System.out.println("after");



Now Execution order is
 first "Before" is getting printed
 thn  "Sameeeeeeeee"
 followed by "============="
         "after"
         "Before"
         "errrrrr"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [rules-users] How handle exception thrown while looping in DRL file

laune
Is this exactly (!) what you have in your rule, between 'when' and 'then'?
     when
        $a:AgentCSVBean()
     then
-W



On 17/07/2012, ashwindrool <[hidden email]> wrote:

> HI Laune ,
>
> I did required changes in code by adding if condition before for loop
>
> *System.out.println("Before");
>   if($a.getAgentList() != null ){
>   System.out.println("--sameeeeeeeeee=====");
>      }
>  for(Integer agentList: $a.getAgentList()) {
>  System.out.println("-==========-");
>     if($a.getAgentList() != null ){
>   System.out.println("--sam====="+agentList);
>      }
>      else{
>      System.out.println("null");
>      }
>     }
>      System.out.println("after");*
>
>
> Now Execution order is
>  f*irst "Before" is getting printed
>  thn  "Sameeeeeeeee"
>  followed by "============="
>          *"after"
>          "Before"
>          "errrrrr"**
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/How-handle-exception-thrown-while-looping-in-DRL-file-tp4018727p4018740.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> [hidden email]
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Loading...