[rules-users] Problem with removePackage()

Edson Tirelli tirelli at post.com
Tue Nov 6 05:57:26 EST 2007


    Yes, looks like a bug. May I ask you please to open a JIRA for it
attaching your example?
    I will track it down and fix.

    Thanks
        Edson

2007/11/6, igor_b <igorbolic at gmail.com>:
>
>
> Hi Edson,
>
> sorry for a late reply. I found out that there is problem in DRL file i.e.
> i
> cannot use
>
>
> package com.sample.mypackage
>
> rule "Apply discount"
>         no-loop true
>         when
>                 $order: Order();
>                 $items : ArrayList() from collect (OrderItem() from
> $order.items)
>         then
>                 #apply discount
> end
>
> when i try to remove previous package from ruleBase object, i get the
> error:
>
> java.lang.IllegalArgumentException: Cannot remove a sink, when the list of
> sinks is null
>         at org.drools.reteoo.ObjectSource.removeObjectSink(
> ObjectSource.java:116)
>         at org.drools.reteoo.AlphaNode.remove(AlphaNode.java:181)
>         at
> org.drools.reteoo.LeftInputAdapterNode.remove(LeftInputAdapterNode.java
> :204)
>         at org.drools.reteoo.FromNode.remove(FromNode.java:153)
>         at
> org.drools.reteoo.RightInputAdapterNode.remove(RightInputAdapterNode.java
> :167)
>         at org.drools.reteoo.BetaNode.remove(BetaNode.java:186)
>         at org.drools.reteoo.RuleTerminalNode.remove(RuleTerminalNode.java
> :461)
>         at org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java
> :224)
>         at org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java
> :272)
>         at
> org.drools.common.AbstractRuleBase.removePackage(AbstractRuleBase.java
> :460)
>         ...
>
>
> instead, i implemented the same thing this way:
>
>
> package com.sample.mypackage
>
>
> rule "Explode Cart"
>         salience 11
>         dialect "java"
>         when
>                 $order: Order()
>                 $item : OrderItem() from $order.items
>         then
>                 insert( $item );
> end
>
>
> rule "Apply discount"
>         no-loop true
>         when
>                 $order : Order();
>                 $items : ArrayList() from collect (OrderItem())
>         then
>                 #apply discount
> end
>
>
> if this is a bug, i hope it'll help finding it and fixing.
>
> Kind regards!
>
>
>
>
> Edson Tirelli-3 wrote:
> >
> >    Igor,
> >
> >    Looks like a bug to me... can you please open a JIRA and attach a
> self
> > contained test case showing the problem? This will speed up the
> > resolution...
> >
> >    Thanks
> >       Edson
> >
> > 2007/11/1, igor_b <igorbolic at gmail.com>:
> >>
> >>
> >> Hi Edson,
> >>
> >> thanx for answering, i've tried 4.0.3, but i get the following error
> when
> >> i
> >> try to refresh my rules:
> >>
> >> java.lang.IllegalArgumentException: Cannot remove a sink, when the list
> >> of
> >> sinks is null
> >>         at org.drools.reteoo.ObjectSource.removeObjectSink(
> >> ObjectSource.java:116)
> >>         at org.drools.reteoo.AlphaNode.remove(AlphaNode.java:192)
> >>         at
> >> org.drools.reteoo.LeftInputAdapterNode.remove(LeftInputAdapterNode.java
> >> :189)
> >>         at org.drools.reteoo.BetaNode.remove(BetaNode.java:173)
> >>         at
> >> org.drools.reteoo.RuleTerminalNode.remove(RuleTerminalNode.java
> >> :466)
> >>         at org.drools.reteoo.ReteooBuilder.removeRule(
> ReteooBuilder.java
> >> :224)
> >>         at
> >> org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java
> >> :270)
> >>         at org.drools.common.AbstractRuleBase.removeRule(
> >> AbstractRuleBase.java:614)
> >>         at
> >> org.drools.common.AbstractRuleBase.removePackage(AbstractRuleBase.java
> >> :531)
> >>         ...
> >>
> >>
> >> During refresh i do the following:
> >>       public void refresh() {
> >>                 try {
> >>                         ruleBase.removePackage("org.sample.mypackage");
> >>
> >>                         // reading drl files from direcotry and puting
> >> them
> >> in the package
> >>
> >>                        ...
> >>                        for(int i = 0; i < size; i++ ) {
> >>                                 builder.addPackageFromDrl( new
> >> InputStreamReader(getClass().getResourceAsStream( "package" + i +
> ".drl"
> >> )
> >> )
> >> );;
> >>
> >>                         }
> >>                         if(ruleBase == null) {
> >>                                 ruleBase = RuleBaseFactory.newRuleBase
> ();
> >>                         }
> >>                         ruleBase.addPackage(builder.getPackage());
> >>
> >>
> >>                 } catch(Exception e) {
> >>                         log.error("Error while refreshing rules: ", e);
> >>                 }
> >>         }
> >>
> >> and one of my .drl files (they all belong to the same package) looks
> >> something like this:
> >>
> >> package org.sample.mypackage
> >>
> >> import org.sample.Orders;
> >> import org.sample.OrderItem;
> >> import org.sample.service.OrderService;
> >>
> >> import java.util.ArrayList
> >> import org.apache.log4j.Logger
> >>
> >> global OrderService orderService
> >> global Logger log
> >>
> >> rule "Apply Discount"
> >>         when
> >>                 orders : Orders();
> >>                 items : ArrayList() from collect (
> >>                         OrderItem(value > 100)
> >>                         from order.items)
> >>         then
> >>                 log.debug("Apply Discount");
> >>                 orderService.applyDiscount(items);
> >> end
> >>
> >> were OrderService is a service class that i'm using to do some
> >> calculating.
> >>
> >> Do you have some idea about what could be causing this error?
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Edson Tirelli-3 wrote:
> >> >
> >> >    Can you try 4.0.3? There was some fix for package management
> >> included
> >> > in
> >> > 4.0.2 if I'm not mistaken...
> >> >
> >> >    []s
> >> >    Edson
> >> >
> >> > 2007/10/31, igor_b <igorbolic at gmail.com>:
> >> >>
> >> >>
> >> >> Hi,
> >> >>
> >> >> I'm using drools 4.0.1. I'm first adding one package to my RuleBase
> >> >> object,
> >> >> and everything works just fine:
> >> >>
> >> >> ...
> >> >> builder.addPackageFromDrl(new
> >> InputStreamReader(resource.getInputStream
> >> >> ()));
> >> >>
> >> >> if(ruleBase == null) {
> >> >>         ruleBase = RuleBaseFactory.newRuleBase();
> >> >> }
> >> >> ruleBase.addPackage(builder.getPackage());
> >> >>
> >> >>
> >> >> But after some time i need to refresh my rules, so i'm using
> following
> >> >> code
> >> >> to remove previous package:
> >> >>
> >> >> ruleBase.removePackage("org.sample.mypackage");
> >> >>
> >> >> and i'm getting the following error:
> >> >>
> >> >> java.lang.NullPointerException
> >> >>         at org.drools.reteoo.ReteooBuilder.removeRule(
> >> ReteooBuilder.java
> >> >> :222)
> >> >>         at
> >> >> org.drools.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java
> >> >> :272)
> >> >>         at
> >> >> org.drools.common.AbstractRuleBase.removePackage(
> AbstractRuleBase.java
> >> >> :460)
> >> >>         at
> >> >> com.diosphere.diomedia.common.drools.impl.RulesServiceImpl.refresh(
> >> >> RulesServiceImpl.java:121)
> >> >>         at
> >> >> com.diosphere.diomedia.service.impl.PromotionManagerImpl.refreshDRLs
> (
> >> >> PromotionManagerImpl.java:39)
> >> >>         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
> >> >> uk.ltd.getahead.dwr.impl.ExecuteQuery.execute(ExecuteQuery.java
> >> >> :170)
> >> >>         at
> >> >> uk.ltd.getahead.dwr.impl.DefaultProcessor.doExec(
> DefaultProcessor.java
> >> >> :552)
> >> >>         at
> >> >> uk.ltd.getahead.dwr.impl.DefaultProcessor.handle(
> DefaultProcessor.java
> >> :88)
> >> >>         at uk.ltd.getahead.dwr.DWRServlet.doPost(DWRServlet.java
> :178)
> >> >>         at
> >> javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
> >> >>         at
> >> javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> >> >>         at
> >> >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> >> >> ApplicationFilterChain.java:290)
> >> >>         at
> >> >> org.apache.catalina.core.ApplicationFilterChain.doFilter(
> >> >> ApplicationFilterChain.java:206)
> >> >>         at
> >> >> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(
> >> >> PageFilter.java:118)
> >> >>         at
> >> >> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(
> >> >> PageFilter.java:52)
> >> >>         at
> >> >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> >> >> ApplicationFilterChain.java:235)
> >> >>         at
> >> >> org.apache.catalina.core.ApplicationFilterChain.doFilter(
> >> >> ApplicationFilterChain.java:206)
> >> >>         at
> >> >> net.sf.acegisecurity.util.FilterChainProxy.doFilter(
> >> FilterChainProxy.java
> >> >> :167)
> >> >>         at
> >> >> net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(
> >> >> FilterToBeanProxy.java:120)
> >> >>         at
> >> >> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> >> >> ApplicationFilterChain.java:235)
> >> >>         at
> >> >> org.apache.catalina.core.ApplicationFilterChain.doFilter(
> >> >> ApplicationFilterChain.java:206)
> >> >>         at
> >> >> org.apache.catalina.core.StandardWrapperValve.invoke(
> >> >> StandardWrapperValve.java:230)
> >> >>         at
> >> >> org.apache.catalina.core.StandardContextValve.invoke(
> >> >> StandardContextValve.java:175)
> >> >>         at
> >> >> org.apache.catalina.core.StandardHostValve.invoke(
> >> StandardHostValve.java
> >> >> :128)
> >> >>         at
> >> >> org.apache.catalina.valves.ErrorReportValve.invoke(
> >> ErrorReportValve.java
> >> >> :104)
> >> >>         at
> >> >> org.apache.catalina.core.StandardEngineValve.invoke(
> >> >> StandardEngineValve.java:109)
> >> >>         at
> >> >> org.apache.catalina.connector.CoyoteAdapter.service(
> CoyoteAdapter.java
> >> >> :261)
> >> >>         at
> >> >> org.apache.coyote.http11.Http11Processor.process(
> Http11Processor.java
> >> :844)
> >> >>         at
> >> >>
> >> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process
> >> (
> >> >> Http11Protocol.java:581)
> >> >>         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(
> >> >> JIoEndpoint.java:447)
> >> >>         at java.lang.Thread.run(Thread.java:619)
> >> >>
> >> >> Does anyone have a clue what might be the problem, and how to fix
> it?
> >> >> Kind regards!
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://www.nabble.com/Problem-with-removePackage%28%29-tf4727072.html#a13516014
> >> >> Sent from the drools - user mailing list archive at Nabble.com.
> >> >>
> >> >> _______________________________________________
> >> >> rules-users mailing list
> >> >> rules-users at lists.jboss.org
> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> >   Edson Tirelli
> >> >   Software Engineer - JBoss Rules Core Developer
> >> >   Office: +55 11 3529-6000
> >> >   Mobile: +55 11 9287-5646
> >> >   JBoss, a division of Red Hat @ www.jboss.com
> >> >
> >> > _______________________________________________
> >> > rules-users mailing list
> >> > rules-users at lists.jboss.org
> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Problem-with-removePackage%28%29-tf4727072.html#a13528214
> >> Sent from the drools - user mailing list archive at Nabble.com.
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users at lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >
> >
> >
> > --
> >   Edson Tirelli
> >   Software Engineer - JBoss Rules Core Developer
> >   Office: +55 11 3529-6000
> >   Mobile: +55 11 9287-5646
> >   JBoss, a division of Red Hat @ www.jboss.com
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Problem-with-removePackage%28%29-tf4727072.html#a13602403
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20071106/6e1fafc7/attachment.html 


More information about the rules-users mailing list