Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-872

Certain errors in accumulate functions cause compiler to throw NPE

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.3.0.Final
    • 6.2.0.Final
    • core engine
    • None
    • Hide

      package org.drools.compiler.test;
      import org.drools.compiler.Cheese;
      rule "Foo"
      when
      Cheese( $type := typo )
      accumulate(
      $c : Cheese( type == $type ),
      $cheeses : collectList( $c ) );
      then
      end

      Show
      package org.drools.compiler.test; import org.drools.compiler.Cheese; rule "Foo" when Cheese( $type := typo ) accumulate( $c : Cheese( type == $type ), $cheeses : collectList( $c ) ); then end
    • NEW
    • NEW

    Description

      The problem is caused by implementations of org.drools.compiler.compiler.Dialect.analyzeBlock returning null if an error is encountered. analyzeBlock (and similar methods) is called from a number of places, none of which seem to check the return value. Null checks could be added to all callers, but might it be better to throw an unchecked exception? This could be caught further up the stack in org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addRule where errors and warnings are retrieved from the context.

      Does drools or drools-compiler have an exception handling policy? Is org.drools.compiler.lang.ParseException a suitable exception in this instance?

      Example stack trace:

      java.lang.NullPointerException
      at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.buildAccumulator(JavaAccumulateBuilder.java:237)
      at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.buildExternalFunctionCall(JavaAccumulateBuilder.java:172)
      at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.build(JavaAccumulateBuilder.java:107)
      at org.drools.compiler.rule.builder.dialect.java.JavaAccumulateBuilder.build(JavaAccumulateBuilder.java:72)
      at org.drools.compiler.rule.builder.PatternBuilder.processSource(PatternBuilder.java:311)
      at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:181)
      at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:146)
      at org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:127)
      at org.drools.compiler.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:63)
      at org.drools.compiler.rule.builder.RuleBuilder.build(RuleBuilder.java:99)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addRule(KnowledgeBuilderImpl.java:1759)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.compileRules(KnowledgeBuilderImpl.java:1047)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.compileAllRules(KnowledgeBuilderImpl.java:925)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addPackage(KnowledgeBuilderImpl.java:918)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addPackageFromDrl(KnowledgeBuilderImpl.java:459)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addKnowledgeResource(KnowledgeBuilderImpl.java:679)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:2204)
      at org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:2193)
      at org.drools.compiler.CommonTestMethodBase.loadKnowledgeBaseFromString(CommonTestMethodBase.java:110)
      at org.drools.compiler.integrationtests.AccumulateTest.getKieSessionFromContentStrings(AccumulateTest.java:3014)
      at org.drools.compiler.integrationtests.AccumulateTest.testAccumulateWithCompilationError(AccumulateTest.java:1969)

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            andrew.bickerton_jira Andrew Bickerton (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: