Using the latest JBPM installer demo setup, I have a simple program. It has
an object called person with a name and a salary. In guvonor there is a
simple rule that I scaled back from the original to try to see what is
happening. If I have a condition (salary >= 5000) it gives a null
exception, if I remove the condition it works fine. The new fact is inserted
and I can see it from my program. Just starting experimenting with guvonor
and have been following the threads on changeset but don't have a complete
grasp on it yet.
Thanks in advance,
Jim K.
rule "PersonWIthHighIncome"
no-loop true
dialect "mvel"
when
Person( salary >= 5000 )
then
Person fact0 = new Person();
fact0.setName( "Joe" );
fact0.setSalary( 34465 );
insert(fact0 );
end
This results in the following exception:
java.lang.NullPointerException
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:148)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1016)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:785)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:657)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:190)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:169)
at simpleBank.SimpleBank.createKnowledgeBase(SimpleBank.java:64)
at simpleBank.SimpleBank.main(SimpleBank.java:27)
Code calling the package
package simpleBank;
import java.util.ArrayList;
import java.util.Iterator;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentConfiguration;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class SimpleBank {
public static void main(String[] args) {
try {
// load up the knowledge base
//KnowledgeBase kbase = readKnowledgeBase();
KnowledgeBase kbase = createKnowledgeBase();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
//KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "Test2", 1);
// go ! insert one person
Person person = new Person();
person.setSalary((long) 6000);
person.setName("Jim");
System.out.println(person.getName());
ksession.insert(person);
assertTrue(ksession.getFactCount() == 1);
ksession.fireAllRules();
// rules should have added another fact
assertTrue(ksession.getFactCount() != 1);
ArrayList<Person> listoffacts = new ArrayList(ksession.getObjects());
System.out.println(listoffacts.size());
Iterator<Person> itr = listoffacts.iterator();
while (itr.hasNext()){
Person element = itr.next();
System.out.println(element.getName() + ":" +
element.getSalary().toString());
}
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase createKnowledgeBase() throws Exception{
KnowledgeAgentConfiguration kaconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty( "drools.agent.scanDirectories", "false" );
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test
agent", kaconf );
kagent.applyChangeSet(ResourceFactory.newUrlResource(
"http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/SalesModel/LATEST/ChangeSet.xml"
));
// kagent.applyChangeSet(
ResourceFactory.newClassPathResource("ChangeSet.xml"));
return kagent.getKnowledgeBase();
}
private static void assertTrue(boolean b) {
if (b)
{
System.out.println("Good number of facts");
}
else
{
System.out.println("Bad number of facts");
}
}
}
--
View this message in context:
http://drools.46999.n3.nabble.com/Null-pointer-exception-after-adding-Whe...
Sent from the Drools: User forum mailing list archive at
Nabble.com.