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"><<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>></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'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'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'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"><<a href="mailto:jfullard@progeny.net" target="_blank">jfullard@progeny.net</a>></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've been messing with this for days now and can't get to the bottom of<br>
this. I'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 "timer"<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("SimpleType: " + $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("drools.resource.scanner.interval", "20");<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("drools.agent.scanDirectories", "true");<br>
aconf.setProperty("drools.agent.scanResources", "true");<br>
aconf.setProperty("drools.agent.newInstance", "false");<br>
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);<br>
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent(<br>
"drools agent", kbase, aconf);<br>
<br>
String urlString =<br>
"<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>";<br>
try {<br>
URL url = new URL(urlString);<br>
UrlResource urlResource = (UrlResource) ResourceFactory<br>
.newUrlResource(url);<br>
urlResource.setBasicAuthentication("enabled");<br>
urlResource.setUsername("John");<br>
urlResource.setPassword("");<br>
kagent.applyChangeSet(urlResource);<br>
} catch (Exception e) {<br>
System.out.println("Caught exception: " + 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("Initialize drools complete");<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>