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

Eval error when using multiple declarations

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Duplicate Issue
    • Affects Version/s: 4.0.3
    • Fix Version/s: 4.0.5, 5.0.0.M1
    • Component/s: None
    • Labels:
      None

      Description

      Just started testing Drools 4.0.3, and found rules like the following will cause ClassCastException when invoked

      when
      t1 : T1()
      t2 : T2()
      eval(t2.f1>0)
      then
      ...
      end

      Looked into the source code and found that: in JavaEvalBuilder.java
      final Declaration[] declarations = new Declaration[usedIdentifiers[0].size()];
      for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ )

      { declarations[i] = context.getDeclarationResolver().getDeclaration( (String) usedIdentifiers[0].get( i ) ); }

      This only retrieves the declarations used in the eval, which in the example include only t2. So the Drools generated code for the eval is like:
      ...
      T2 t2 = (T2) declarations[0].getValue( (org.drools.common.InternalWorkingMemory) workingMemory, ( (org.drools.common.InternalFactHandle) tuple.get( declarations[0] ) ).getObject() );
      ...

      which cause ClassCastException at runtime because the declarations[0] passed in is actually t1.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: