Uploaded image for project: 'Red Hat Decision Manager'
  1. Red Hat Decision Manager
  2. RHDM-1622

Statement ending with a new line character (not semi-colon) in action part causes compilation error or unexpected result in executable model.

    XMLWordPrintable

Details

    • Bug
    • Status: Verified (View Workflow)
    • Major
    • Resolution: Done
    • 7.10.0.GA
    • 7.11.0.GA
    • BRE
    • CR1
    • Hide
      1. Extract reproducer.
        $ unzip reproducer_model_compiler_22a.zip
        $ cd reproducer_model_compiler_22a
        
      2. Run run_mvn script. This script runs mvn clean compile exec:exec with -DgenerateModel=NO first and runs with -DgenerateModel=YES next.
        $ ./run_mvn
        
      Show
      Extract reproducer. $ unzip reproducer_model_compiler_22a.zip $ cd reproducer_model_compiler_22a Run run_mvn script. This script runs mvn clean compile exec:exec with -DgenerateModel=NO first and runs with -DgenerateModel=YES next. $ ./run_mvn
    • 2021 Week 10-12 (from Mar 8)
    • +

    Description

      When building and executing a rule that is written in MVEL dialect and contains a statement ending with a new line character (not semi-colon) in action part with executable model enabled, we sometimes encounter some compilation error or unexpected result.

      • Example 1 (rule "rule22a1" in reproducer_model_compiler_22a)
        This rule (*1) contains a statement ending with a new line character (*1-1). When building this rule, model compiler generates java code like (*2) from the action part and the generated code causes a compilation error like (*3).
        (*1)
        package com.example.reproducer
        
        import java.math.BigDecimal
        
        dialect "mvel"
        
        rule "rule22a1"
            when
                $bus : Bus( $weight : weight != 0 )
            then
                System.out.println("***** Action of rule22a1: " + $bus + ", $weight = " + $weight);
                $weight = $weight    // .......... (*1-1)
                BigDecimal bd1 = 0;
                modify($bus) {
                    weight = bd1
                }
        end
        

        (*2)

                System.out.println("***** Action of rule22a1: " + $bus + ", $weight = " + $weight);
                $weight = new java.math.BigDecimal(0);    // ..... (*2-1)
                $bus.setWeight(bd1);
                drools.update($bus, mask_$bus);
        

        (*3)

        17:28:50.182 [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile-1) @ reproducer_model_compiler_22a ---
        17:28:50.185 [INFO] Changes detected - recompiling the module!
        17:28:50.186 [INFO] Compiling 9 source files to /work2/testdir/reproducer_model_compiler_22a/target/classes
        17:28:50.459 [INFO] -------------------------------------------------------------
        17:28:50.459 [ERROR] COMPILATION ERROR : 
        17:28:50.459 [INFO] -------------------------------------------------------------
        17:28:50.459 [ERROR] /work2/testdir/reproducer_model_compiler_22a/target/generated-sources/drools-model-compiler/main/java/com/example/reproducer/P7C/LambdaConsequence7CD56D82A4775FB5FC32E4022E4511B5.java:[25,24] cannot find symbol
          symbol:   variable bd1
          location: class com.example.reproducer.P7C.LambdaConsequence7CD56D82A4775FB5FC32E4022E4511B5
        17:28:50.460 [INFO] 1 error
        17:28:50.460 [INFO] -------------------------------------------------------------
        
      • Example 2 (rule "rule22a2" in reproducer_model_compiler_22a)
        This rule (*4) contains a statement ending with a new line character (*4-1). When building this rule, model compiler generates java code like (*5) from the action part. The generated code does not cause a compilation error but causes unexpected result at runtime like (*6).
        (*4)
        rule "rule22a2"
            when
                $bus : Bus( $weight : weight != 0, $capacity : capacity != 0 )
            then
                System.out.println("***** Action of rule22a2: " + $bus + ", $weight = " + $weight + ", $capacity = " + $capacity);
                $weight = $weight    // .......... (*4-1)
                BigDecimal bd1 = $capacity;
                modify($bus) {
                    weight = $weight
                }
        end
        

        (*5)

                System.out.println("***** Action of rule22a2: " + $bus + ", $weight = " + $weight + ", $capacity = " + $capacity);
                $weight = new java.math.BigDecimal($capacity);    ..... (*5-1)
                $bus.setWeight($weight);
                drools.update($bus, mask_$bus);
        

        (*6)

        ***** start
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 12000, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** Action of rule22a2: com.example.reproducer.Bus@7b64240d, $weight = 25, $capacity = 25
        ***** end
        

      Java code generated by model compiler (*2-1) and (*5-1) are both $weight = <RHS of the next assignment statement> and incorrect.

      In plain drl, both of these examples are successfully built and executed as expected.

      Attachments

        Issue Links

          Activity

            People

              lmolteni@redhat.com Luca Molteni
              rhn-support-myoshida Masato Yoshida
              Daniel Rosa Daniel Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: