We have a number of add/remove rule tests, could you reproduce your problem, using the
same classes and format as outlined in this test class. Ideally adding your reproducer as
a single failing test method:
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test...
Creating JIRA’s and submitting pull requests.
http://docs.jboss.org/drools/release/5.6.0.Final/droolsjbpm-introduction-...
Mark
On 6 Jun 2014, at 09:12, tia <rabarijaonadomoina(a)gmail.com> wrote:
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.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users