If the event type is fully declared in DRL, the NPE does not occur.<br><br>What is the difference between DRL being compiled in the course of a ChangeSet in contrast to being compiled by a KnowledgeBuilder?<br><br>-W<br><br>
<br><br><div class="gmail_quote">On 13 July 2011 15:05, Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m pretty sure that this is a bug. When compiling a DRL from a Chenge Set, the resulting package<br>in the Knowledge Base does not contain declare&#39;d types that do not contain fields; it only contains declares with at least one field.<br>


<br>This results in a ClassObjectTypeConf with a typeDecl == null, and the damage is done.<br><br>I&#39;d say that this is a show stopper for any combination of ChangeSet / Pojo as Event.<br><font color="#888888"><br>-W <br>
</font><div><div></div><div class="h5"><br><br><div class="gmail_quote">

On 12 July 2011 19:32, John <span dir="ltr">&lt;<a href="mailto:jfullard@progeny.net" target="_blank">jfullard@progeny.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


Hello,<br>
<br>
I&#39;ve been messing with this for days now and can&#39;t get to the bottom of<br>
this.  I&#39;m using drools 5.2.0 Final and setting up my KnowledgeBase with a<br>
KnowledgeAgent which is pulling a package from guvnor (also 5.2.0 Final).  I<br>
do NOT get this error if I use a KnowledgeBuilder and add the exact same drl<br>
file as a resource.<br>
<br>
If the DRL in guvnor has a rule that uses a sliding window, i get an NPE<br>
when trying to insert an object and the following stack trace:<br>
<br>
java.lang.NullPointerException<br>
        at<br>
org.drools.reteoo.ReteooFactHandleFactory.newFactHandle(ReteooFactHandleFactory.java:56)<br>
        at<br>
org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:80)<br>
        at<br>
org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:65)<br>
        at org.drools.common.NamedEntryPoint.createHandle(NamedEntryPoint.java:705)<br>
        at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:282)<br>
        at<br>
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:905)<br>
        at<br>
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:864)<br>
        at<br>
org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:255)<br>
        at john.DroolsError.runRules(DroolsError.java:48)<br>
        at john.DroolsError.main(DroolsError.java:40)<br>
<br>
Here is the DRL:<br>
<br>
1.      |       package drools<br>
2.      |       import simple.SimpleType<br>
3.      |<br>
4.      |<br>
5.      |<br>
6.      |<br>
7.      |<br>
8.      |<br>
9.      |       import simple.SimpleType;<br>
10.     |<br>
11.     |       declare SimpleType<br>
12.     |           @role(event)<br>
13.     |       end<br>
14.     |<br>
15.     |       rule &quot;timer&quot;<br>
16.     |       timer (cron:5/5 * * * * ?)<br>
17.     |       when<br>
18.     |           $newest : Number()<br>
19.     |               from accumulate( SimpleType ($num : number) over<br>
window:time(5s),<br>
20.     |                   max($num) )<br>
21.     |           $st : SimpleType( number == $newest.intValue )<br>
22.     |       then<br>
23.     |           System.out.println(&quot;SimpleType: &quot; + $st.number);<br>
24.     |       end<br>
(note: the first import of simple.SimpleType comes from the package<br>
configuration in guvnor, the second is in the drl file itself. the file will<br>
not validate without the import explicitly listed there, saying the type is<br>
not declared as an event...)<br>
<br>
Here is the Java code:<br>
<br>
ResourceChangeScannerConfiguration sconf = ResourceFactory<br>
                                .getResourceChangeScannerService()<br>
                                .newResourceChangeScannerConfiguration();<br>
                sconf.setProperty(&quot;drools.resource.scanner.interval&quot;, &quot;20&quot;);<br>
                ResourceFactory.getResourceChangeScannerService().configure(sconf);<br>
<br>
                KnowledgeBaseConfiguration config = KnowledgeBaseFactory<br>
                                .newKnowledgeBaseConfiguration();<br>
                config.setOption(EventProcessingOption.STREAM);<br>
<br>
                KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory<br>
                                .newKnowledgeAgentConfiguration();<br>
                aconf.setProperty(&quot;drools.agent.scanDirectories&quot;, &quot;true&quot;);<br>
                aconf.setProperty(&quot;drools.agent.scanResources&quot;, &quot;true&quot;);<br>
                aconf.setProperty(&quot;drools.agent.newInstance&quot;, &quot;false&quot;);<br>
                KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);<br>
                KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent(<br>
                                &quot;drools agent&quot;, kbase, aconf);<br>
<br>
                String urlString =<br>
&quot;<a href="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/drools/LATEST/ChangeSet.xml" target="_blank">http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/drools/LATEST/ChangeSet.xml</a>&quot;;<br>



                try {<br>
                        URL url = new URL(urlString);<br>
                        UrlResource urlResource = (UrlResource) ResourceFactory<br>
                                        .newUrlResource(url);<br>
                        urlResource.setBasicAuthentication(&quot;enabled&quot;);<br>
                        urlResource.setUsername(&quot;John&quot;);<br>
                        urlResource.setPassword(&quot;&quot;);<br>
                        kagent.applyChangeSet(urlResource);<br>
                } catch (Exception e) {<br>
                        System.out.println(&quot;Caught exception: &quot; + e.getMessage());<br>
                        e.printStackTrace();<br>
                }<br>
<br>
                ResourceFactory.getResourceChangeNotifierService().start();<br>
                ResourceFactory.getResourceChangeScannerService().start();<br>
<br>
                StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();<br>
                System.out.println(&quot;Initialize drools complete&quot;);<br>
<br>
                SimpleType simp = new SimpleType();<br>
                simp.setNumber(5);<br>
<br>
                ksession.insert(simp);<br>
<br>
Thanks,<br>
John<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/NPE-on-fact-insertion-if-rule-has-sliding-window-tp3163261p3163261.html" target="_blank">http://drools.46999.n3.nabble.com/NPE-on-fact-insertion-if-rule-has-sliding-window-tp3163261p3163261.html</a><br>



Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br>
</div></div></blockquote></div><br>