Hello,
I'm trying to add a new rule on the fly like here:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test...
Here is the method to add a rule, once the KieSession is created and
configured:
public void addRule(String rule){
KieServices ks= KieServices.Factory.get();
ReleaseId rid= ks.newReleaseId("org.kie", "businessrules",
"1.0");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(rid);
kfs.write("src/main/resources/rule.drl",rule);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
if( kb.getResults().hasMessages( org.kie.api.builder.Message.Level.ERROR )
) {
for( org.kie.api.builder.Message result : kb.getResults().getMessages() )
{
System.err.println(result.getText());
}
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository()
.getKieModule(rid);
byte[] jar = kieModule.getBytes();
Resource jarRes = ks.getResources().newByteArrayResource(jar);
ks.getRepository().addKieModule(jarRes);
kieContainer.updateToVersion(rid);
}
But when I'm calling this method, I get the error below:
java.lang.NullPointerException
at org.drools.core.util.LinkedList.remove(LinkedList.java:168)
at
org.drools.core.phreak.AddRemoveRule.mergeSegment(AddRemoveRule.java:938)
at
org.drools.core.phreak.AddRemoveRule.correctSegmentOnSplitOnRemove(AddRemoveRule.java:377)
at org.drools.core.phreak.AddRemoveRule.removeRule(AddRemoveRule.java:182)
at
org.drools.core.reteoo.ReteooBuilder.removeTerminalNode(ReteooBuilder.java:171)
at org.drools.core.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:165)
at
org.drools.core.reteoo.ReteooRuleBase.removeRule(ReteooRuleBase.java:1406)
at
org.drools.core.reteoo.ReteooRuleBase.removeObjectsGeneratedFromResource(ReteooRuleBase.java:1652)
at
org.drools.compiler.compiler.PackageBuilder.removeObjectsGeneratedFromResource(PackageBuilder.java:3898)
at
org.drools.compiler.kie.builder.impl.KieContainerImpl.updateToVersion(KieContainerImpl.java:114)
For the line : "kieContainer.updateToVersion(rid);"
But if I'm firing the rules once (kieSession.fireAllRules();) before adding
the new rule, I don't get the exception O_o
Someone has any idea why ?
thanks!
--
View this message in context:
http://drools.46999.n3.nabble.com/NullPointerException-at-org-drools-comp...
Sent from the Drools: User forum mailing list archive at
Nabble.com.