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

NPE when compiling rule consequences

    XMLWordPrintable

    Details

      Description

      I have the following code: (note String[] ruleFiles contains only one string)

      public class Engine {

      private static RuleBase ruleBase;

      public void start(String[] ruleFiles) throws Exception {

      PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();

      JavaDialectConfiguration javaConf = (JavaDialectConfiguration) cfg.getDialectConfiguration("java");

      javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);

      PackageBuilder builder = new PackageBuilder(cfg);

      for (String file : ruleFiles)

      { builder.addPackageFromDrl(new InputStreamReader(ClassLoader.getSystemResourceAsStream(file))); }

      Package pkg = builder.getPackage();

      PackageBuilderErrors errors = builder.getErrors();

      if (errors.getErrors().length != 0)

      { // do something }

      RuleBaseConfiguration conf = new RuleBaseConfiguration();

      conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);

      ruleBase = RuleBaseFactory.newRuleBase();

      ruleBase.addPackage(pkg);

      ruleBase.newStatefulSession(false);

      }

      }

      At the builder.addPackageFromDrl(new InputStreamReader(ClassLoader.getSystemResourceAsStream(file))); line I'm getting the following exception:

      java.lang.NullPointerException

      at org.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConsequenceBuilder.java:54)

      at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:67)

      at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)

      at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)

      at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)

      at myPackage.rivoli.service.rules.Engine.start(Engine.java:33)

      at myPackage.rivoli.rules.LeaderKingAndHeirTest.setUp(LeaderKingAndHeirTest.java:26)

      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)

      I am using Drools 4.0.3

      I have the following jars in my class path:

      antlr-runtime-3.0.jar

      core-3.2.3.v_686_R32x.jar

      drools-compiler-4.0.3.jar

      drools-core-4.0.3.jar

      mvel14-1.2.10.jar

      Any ideas would be helpful. Thanks.

      rule "leaders in same location"

      salience 10

      when

      $result : RuleResult(rulesPassed not contains "leaders in same location")

      $loc : LocationImpl()

      $leaderName : String()

      $leader1 : LeaderImpl(name == $leaderName, location == $loc)

      $leader2 : LeaderImpl(name != $leaderName, this != $leader1, location == $loc)

      then

      $result.addPassedRule(leaders in same location);

      update($result);

      end

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                tirelli Edson Tirelli
                Reporter:
                tirelli Edson Tirelli
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: