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

Drools condition part always use MVEL strict mode (extended classes doen't get properties of super class )

XMLWordPrintable

    • Hide

      Run Following DRL file, which gives compilation error
      [Error: unable to resolve method using strict-mode: defaultpkg.Test.Price()]
      [Near :

      {... Price < 100 ....}

      ]

      //Start test.drl rules
      import java.util.HashMap;

      declare HashMap
      end

      declare Test extends HashMap
      end

      rule "Insert"
      salience 0
      when
      then
      Test t = new Test();
      t.Price = 10;
      t.put("A", "a");
      t.OtherPrices = new HashMap();
      t.OtherPrices.OldPrice = 8;
      //This as well doesn't print content as per toString() of HashMap is there a way to do that?
      System.out.println("Inserting t="+t);
      insert(t);
      end

      rule "Test HashMap"
      salience -1
      when
      t: HashMap(
      Price < 11
      )
      then
      t.Price = 11;
      System.out.println("In Test HashMap");
      end

      rule "Test Inherited"
      salience -1
      when
      t: Test(
      Price<100
      )
      then
      t.Price = 12;
      System.out.println("In Test Inherited!");
      end

      rule "Print Result"
      salience -5
      when
      t: Test()
      then
      System.out.println("Finally Price is ="+t.Price);
      //This as well doesn't print content as per toString() of HashMap is there a way to do that?
      System.out.println("Finally t="+t);
      end

      Show
      Run Following DRL file, which gives compilation error [Error: unable to resolve method using strict-mode: defaultpkg.Test.Price()] [Near : {... Price < 100 ....} ] //Start test.drl rules import java.util.HashMap; declare HashMap end declare Test extends HashMap end rule "Insert" salience 0 when then Test t = new Test(); t.Price = 10; t.put("A", "a"); t.OtherPrices = new HashMap(); t.OtherPrices.OldPrice = 8; //This as well doesn't print content as per toString() of HashMap is there a way to do that? System.out.println("Inserting t="+t); insert(t); end rule "Test HashMap" salience -1 when t: HashMap( Price < 11 ) then t.Price = 11; System.out.println("In Test HashMap"); end rule "Test Inherited" salience -1 when t: Test( Price<100 ) then t.Price = 12; System.out.println("In Test Inherited!"); end rule "Print Result" salience -5 when t: Test() then System.out.println("Finally Price is ="+t.Price); //This as well doesn't print content as per toString() of HashMap is there a way to do that? System.out.println("Finally t="+t); end

      Even after setting MVEL strict mode to false, condition part of drools works using strict mode and can't work with Inherited getters of HashMap (Breaks lot of working rules from 5.4)
      Error: [Error: unable to resolve method using strict-mode: defaultpkg.Test.Price()]
      [Near :

      {... Price < 100 ....}

      ]
      ...
      t: HashMap(
      Price < 11
      )
      ..
      Does work but

      import java.util.HashMap;

      declare HashMap
      end

      declare Test extends HashMap
      end

      t: Test(
      Price<100
      )

      doesn't work (please see full rules in steps to reproduce)

      Even condition
      this["OtherPrices"]["OldPrice"] < 9
      does work for Map but not for inherited Test class
      (applicable but not included in sample code to reproduce issue, added drl for this as attachment)

              mfusco@redhat.com Mario Fusco
              stamboli_jira Shailesh T (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: