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

Drools condition cannot retrieve object from Map with Enum key

    XMLWordPrintable

Details

    • Hide

      A fact :

          public class Convention {
            private Map<ECommissionType, List<Commission>> commissions = new HashMap<>();
          }
      

      An enumeration :

          public enum ECommissionType {
            ACQ,RIS,POF,[...]
          }
      

      And a rule condition assuming $convention is properly initialized in a former condition and is an instance of the Convention class shown) :

           $comm : Commission() from $convention.getCommissions().get(ECommissionType.$1)
      

      Compilation using kie-maven-plugin is raising an error :

      Unable to Analyse Expression $convention.getCommissions().get(ECommissionType.RIS)):
      sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class : [Rule name='B_CommissionLigne_98']
      
      Show
      A fact : public class Convention { private Map<ECommissionType, List<Commission>> commissions = new HashMap<>(); } An enumeration : public enum ECommissionType { ACQ,RIS,POF,[...] } And a rule condition assuming $convention is properly initialized in a former condition and is an instance of the Convention class shown) : $comm : Commission() from $convention.getCommissions().get(ECommissionType.$1) Compilation using kie-maven-plugin is raising an error : Unable to Analyse Expression $convention.getCommissions().get(ECommissionType.RIS)): sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang. Class : [Rule name= 'B_CommissionLigne_98' ]
    • Workaround Exists
    • Hide

      As proposed on the stackoverflow topic, this works :

      rule comms
      when
        $conv: Convention()
        $comm: Comm() from (ArrayList)($conv.getComms()).get(Type.AAA)
      then [...]
      

      Please note the difference is an ArrayList cast (with a few parentheses).

      Show
      As proposed on the stackoverflow topic, this works : rule comms when $conv: Convention() $comm: Comm() from (ArrayList)($conv.getComms()).get(Type.AAA) then [...] Please note the difference is an ArrayList cast (with a few parentheses).
    • NEW
    • NEW
    • 41461468

    Description

      I'm migrating an application that used drools 5.3 on the newer drools 6.5 version.
      I'm using a decision table, And one of my condition is accessing a Map which has an enum class as a key. It is not compiling unless I do a strange ArrayList cast.

      Please refer to this stackoverflow topic for details.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            Lordsephiroth Patrick Mingard (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: