// write compiled rules to disk
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename + ".temp"));
out.writeObject(kbuilder.getKnowledgePackages());
out.close();
On a later stage, i load all files holding compiled rules, one at a time, so i can use the knowledge base and create the knowledge session. Here's what i'm doing for each of the generated compiled files:
in = new ObjectInputStream(new FileInputStream(filename)); // the ones *.temp
kpkgs = (Collection<KnowledgePackage>) in.readObject();
kbase.addKnowledgePackages(kpkgs);
in.close();
This all works apparently well. Drools loads the sum of all rules defined in each smaller XML file. However, whenever i try to insert a fact into memory, i get an exception, just like the following:
java.lang.NullPointerException
at org.drools.base.ClassFieldReader.getValue(ClassFieldReader.java:91)
at org.drools.base.evaluators.EqualityEvaluatorsDefinition$StringEqualEvaluator.evaluate(EqualityEvaluatorsDefinition.java:1962)
at org.drools.rule.LiteralRestriction.isAllowed(LiteralRestriction.java:92)
at org.drools.rule.OrCompositeRestriction.isAllowed(OrCompositeRestriction.java:25)
at org.drools.rule.MultiRestrictionFieldConstraint.isAllowed(MultiRestrictionFieldConstraint.java:97)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:143)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:360)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:344)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:185)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:146)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1046)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1001)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:788)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:216)
at pt.itsd.probe.ConfigurationSetup.parseAndCompileConfigFiles(ConfigurationSetup.java:316)
at pt.itsd.probe.ConfigurationSetup.main(ConfigurationSetup.java:131)
I have done some testing and I am unable to trace this exception to any particular rule, or event any XML chunck. If i load the entire XML file it takes a lot of memory compiling but it works in the end. Also, if i remove all the <or-restriction-connective> tags, it also works no matter if i load them to kbase.
Is there something i can do? or maybe another way of doing it? Any help is much appreciated.
I'm using drools 5.0.0 from main download page.
_ miguel