Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-1982

NullPointerException when executing rule sample

    XMLWordPrintable

Details

    Description

      Hi!

      I have somewhat non-standard running environment - springsource sever. Because spring requires everything to be provided as bundle, i created drools bundle. I unpacked (extract) all drools jar-s except drools-clips, drools-jsr94 and drools-process-enterprise into single directory, and then created one big jar. Then i converted this jar using bnd utility to bundle. Because springsource uses older antlr, i did copy antlr-runtime-3.1.1 into bundle, to classes inside use this version.

      In eclipse i created new project, and created helloworld sample. I did manage successfully to execute RuleFlowTest! But, DroolsTest fails with:

      [2009-02-26 17:18:35.245] server-dm-8 System.err E org.drools.runtime.rule.ConsequenceException: java.lang.NullPointerException
      [2009-02-26 17:18:35.245] server-dm-8 System.err E at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
      [2009-02-26 17:18:35.245] server-dm-8 System.err E at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:935)
      [2009-02-26 17:18:35.245] server-dm-8 System.err E at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:882)
      [2009-02-26 17:18:35.246] server-dm-8 System.err E at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1072)
      [2009-02-26 17:18:35.246] server-dm-8 System.err E at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:616)
      [2009-02-26 17:18:35.246] server-dm-8 System.err E at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:583)
      [2009-02-26 17:18:35.246] server-dm-8 System.err E at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:151)
      [2009-02-26 17:18:35.246] server-dm-8 System.err E at com.sample.DroolsTest.main(DroolsTest.java:33)
      [2009-02-26 17:18:35.246] server-dm-8 System.err E at com.sample.Runner.init(Runner.java:16)
      [2009-02-26 17:18:35.247] server-dm-8 System.err E at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [2009-02-26 17:18:35.247] server-dm-8 System.err E at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      [2009-02-26 17:18:35.247] server-dm-8 System.err E at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      [2009-02-26 17:18:35.247] server-dm-8 System.err E at java.lang.reflect.Method.invoke(Method.java:597)
      [2009-02-26 17:18:35.248] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1414)
      [2009-02-26 17:18:35.248] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1375)
      [2009-02-26 17:18:35.248] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
      [2009-02-26 17:18:35.248] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
      [2009-02-26 17:18:35.248] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
      [2009-02-26 17:18:35.248] server-dm-8 System.err E at java.security.AccessController.doPrivileged(Native Method)
      [2009-02-26 17:18:35.249] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
      [2009-02-26 17:18:35.249] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
      [2009-02-26 17:18:35.249] server-dm-8 System.err E at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      [2009-02-26 17:18:35.249] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
      [2009-02-26 17:18:35.250] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
      [2009-02-26 17:18:35.250] server-dm-8 System.err E at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
      [2009-02-26 17:18:35.250] server-dm-8 System.err E at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
      [2009-02-26 17:18:35.250] server-dm-8 System.err E at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
      [2009-02-26 17:18:35.251] server-dm-8 System.err E at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:288)
      [2009-02-26 17:18:35.251] server-dm-8 System.err E at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:145)
      [2009-02-26 17:18:35.252] server-dm-8 System.err E at com.springsource.server.kernel.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:82)
      [2009-02-26 17:18:35.252] server-dm-8 System.err E at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      [2009-02-26 17:18:35.252] server-dm-8 System.err E at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      [2009-02-26 17:18:35.253] server-dm-8 System.err E at java.lang.Thread.run(Thread.java:619)
      [2009-02-26 17:18:35.253] server-dm-8 System.err E Caused by: java.lang.NullPointerException
      [2009-02-26 17:18:35.254] server-dm-8 System.err E at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:926)
      [2009-02-26 17:18:35.254] server-dm-8 System.err E ... 31 more

      Drools file which is executed is:

      package com.sample

      import com.sample.DroolsTest.Message;

      rule "Hello World"
      when
      m : Message( status == Message.HELLO, message : message )
      then
      System.out.println( "Ssssss" );
      m.setMessage( "Goodbye cruel world" );
      m.setStatus( Message.GOODBYE );
      update( m );
      end

      rule "GoodBye"
      when
      Message( status == Message.GOODBYE, message : message )
      then
      System.out.println( message );
      end

      And DroolsTest java is also unmodified:

      package com.sample;

      import org.drools.KnowledgeBase;
      import org.drools.KnowledgeBaseFactory;
      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;

      /**

      • This is a sample class to launch a rule.
        */
        public class DroolsTest {

      public static final void main(String[] args) {
      try

      { // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test"); // go ! Message message = new Message(); message.setMessage("Hello World"); message.setStatus(Message.HELLO); ksession.insert(message); ksession.fireAllRules(); logger.close(); }

      catch (Throwable t)

      { t.printStackTrace(); }

      }

      private static KnowledgeBase readKnowledgeBase() throws Exception {
      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"), ResourceType.DRL);
      KnowledgeBuilderErrors errors = kbuilder.getErrors();
      if (errors.size() > 0) {
      for (KnowledgeBuilderError error: errors)

      { System.err.println(error); }

      throw new IllegalArgumentException("Could not parse knowledge.");
      }
      KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
      kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
      return kbase;
      }

      public static class Message {

      public static final int HELLO = 0;
      public static final int GOODBYE = 1;

      private String message;

      private int status;

      public String getMessage()

      { return this.message; }

      public void setMessage(String message)

      { this.message = message; }

      public int getStatus()

      { return this.status; }

      public void setStatus(int status)

      { this.status = status; }

      }

      }

      I did try to browse trough source and try to find out what the problem could be, but at no avail.

      Attachments

        Activity

          People

            mproctor@redhat.com Mark Proctor
            hhabjan_jira Hrvoje Habjanic (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: