[rules-dev] [rules-users] NPE on fact insertion if rule has sliding window

Wolfgang Laun wolfgang.laun at gmail.com
Wed Jul 13 09:55:21 EDT 2011


If the event type is fully declared in DRL, the NPE does not occur.

What is the difference between DRL being compiled in the course of a
ChangeSet in contrast to being compiled by a KnowledgeBuilder?

-W



On 13 July 2011 15:05, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:

> I'm pretty sure that this is a bug. When compiling a DRL from a Chenge Set,
> the resulting package
> in the Knowledge Base does not contain declare'd types that do not contain
> fields; it only contains declares with at least one field.
>
> This results in a ClassObjectTypeConf with a typeDecl == null, and the
> damage is done.
>
> I'd say that this is a show stopper for any combination of ChangeSet / Pojo
> as Event.
>
> -W
>
>
> On 12 July 2011 19:32, John <jfullard at progeny.net> wrote:
>
>> Hello,
>>
>> I've been messing with this for days now and can't get to the bottom of
>> this.  I'm using drools 5.2.0 Final and setting up my KnowledgeBase with a
>> KnowledgeAgent which is pulling a package from guvnor (also 5.2.0 Final).
>>  I
>> do NOT get this error if I use a KnowledgeBuilder and add the exact same
>> drl
>> file as a resource.
>>
>> If the DRL in guvnor has a rule that uses a sliding window, i get an NPE
>> when trying to insert an object and the following stack trace:
>>
>> java.lang.NullPointerException
>>        at
>>
>> org.drools.reteoo.ReteooFactHandleFactory.newFactHandle(ReteooFactHandleFactory.java:56)
>>        at
>>
>> org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:80)
>>        at
>>
>> org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:65)
>>        at
>> org.drools.common.NamedEntryPoint.createHandle(NamedEntryPoint.java:705)
>>        at
>> org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:282)
>>        at
>>
>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:905)
>>        at
>>
>> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:864)
>>        at
>>
>> org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:255)
>>        at john.DroolsError.runRules(DroolsError.java:48)
>>        at john.DroolsError.main(DroolsError.java:40)
>>
>> Here is the DRL:
>>
>> 1.      |       package drools
>> 2.      |       import simple.SimpleType
>> 3.      |
>> 4.      |
>> 5.      |
>> 6.      |
>> 7.      |
>> 8.      |
>> 9.      |       import simple.SimpleType;
>> 10.     |
>> 11.     |       declare SimpleType
>> 12.     |           @role(event)
>> 13.     |       end
>> 14.     |
>> 15.     |       rule "timer"
>> 16.     |       timer (cron:5/5 * * * * ?)
>> 17.     |       when
>> 18.     |           $newest : Number()
>> 19.     |               from accumulate( SimpleType ($num : number) over
>> window:time(5s),
>> 20.     |                   max($num) )
>> 21.     |           $st : SimpleType( number == $newest.intValue )
>> 22.     |       then
>> 23.     |           System.out.println("SimpleType: " + $st.number);
>> 24.     |       end
>> (note: the first import of simple.SimpleType comes from the package
>> configuration in guvnor, the second is in the drl file itself. the file
>> will
>> not validate without the import explicitly listed there, saying the type
>> is
>> not declared as an event...)
>>
>> Here is the Java code:
>>
>> ResourceChangeScannerConfiguration sconf = ResourceFactory
>>                                .getResourceChangeScannerService()
>>                                .newResourceChangeScannerConfiguration();
>>                sconf.setProperty("drools.resource.scanner.interval",
>> "20");
>>
>>  ResourceFactory.getResourceChangeScannerService().configure(sconf);
>>
>>                KnowledgeBaseConfiguration config = KnowledgeBaseFactory
>>                                .newKnowledgeBaseConfiguration();
>>                config.setOption(EventProcessingOption.STREAM);
>>
>>                KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory
>>                                .newKnowledgeAgentConfiguration();
>>                aconf.setProperty("drools.agent.scanDirectories", "true");
>>                aconf.setProperty("drools.agent.scanResources", "true");
>>                aconf.setProperty("drools.agent.newInstance", "false");
>>                KnowledgeBase kbase =
>> KnowledgeBaseFactory.newKnowledgeBase(config);
>>                KnowledgeAgent kagent =
>> KnowledgeAgentFactory.newKnowledgeAgent(
>>                                "drools agent", kbase, aconf);
>>
>>                String urlString =
>> "
>> http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/drools/LATEST/ChangeSet.xml
>> ";
>>                try {
>>                        URL url = new URL(urlString);
>>                        UrlResource urlResource = (UrlResource)
>> ResourceFactory
>>                                        .newUrlResource(url);
>>                        urlResource.setBasicAuthentication("enabled");
>>                        urlResource.setUsername("John");
>>                        urlResource.setPassword("");
>>                        kagent.applyChangeSet(urlResource);
>>                } catch (Exception e) {
>>                        System.out.println("Caught exception: " +
>> e.getMessage());
>>                        e.printStackTrace();
>>                }
>>
>>                ResourceFactory.getResourceChangeNotifierService().start();
>>                ResourceFactory.getResourceChangeScannerService().start();
>>
>>                StatefulKnowledgeSession ksession =
>> kbase.newStatefulKnowledgeSession();
>>                System.out.println("Initialize drools complete");
>>
>>                SimpleType simp = new SimpleType();
>>                simp.setNumber(5);
>>
>>                ksession.insert(simp);
>>
>> Thanks,
>> John
>>
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/NPE-on-fact-insertion-if-rule-has-sliding-window-tp3163261p3163261.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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20110713/6a9a3634/attachment.html 


More information about the rules-dev mailing list