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

MVEL runtime allowed casting primitives to String, executable model doesn't

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not a Bug
    • Icon: Major Major
    • None
    • 7.73.0.Final
    • executable model
    • None
    • Hide

      In project https://github.com/flozano/drools-issues, class CastTest, test intToString

      Show
      In project https://github.com/flozano/drools-issues , class CastTest , test intToString
    • Set a Value
    • NEW
    • NEW
    • ---
    • ---

      Before executable model, you could cast a primitive type (and its boxed counterparts if I'm not mistaken) to String.

      After enabling executable model, an error happens when trying to build a DRL that contains such construct.

      For example:

      // DRL directly from drools/issues/CastTest_intToString.drl
      package drools.issues;
      global drools.issues.model.RegardsManager regardsManager;
      dialect "mvel"
      
      rule "Send regards to all Tesla owners"
      	when
      		$v:drools.issues.model.vehicles.ElectricCar(maker=='Tesla')
      	then
      		insert(regardsManager.requestSendRegards("Hi, owner of a Tesla!").withParam("score", (String) $v.score ));
      end
      
      //
      

      withParam is defined as:

      	public SendRegards withParam(String name, String value) {
      		params.put(name, Objects.requireNonNull(value));
      		return this;
      	}
      

      and score is an integer.

      With all above, MVEL runtime works well while executable model yields this:

      [main] ERROR drools.issues.executor.DroolsInternalFactory - KieBuilder has errors (releaseId=drools.issues.rules:CastTest_intToString.drl:1.0.0): Error Messages:
      Message [id=1, level=ERROR, path=src/main/java/drools/issues/P56/LambdaConsequence56D5C9B4A166C62ADD965E3D4746CC56.java, line=20, column=968
         text=Cannot cast from int to String]
      Message [id=2, level=ERROR, path=src/main/java/drools/issues/P56/LambdaConsequence56D5C9B4A166C62ADD965E3D4746CC56.java, line=0, column=0
         text=Java source of src/main/java/drools/issues/P56/LambdaConsequence56D5C9B4A166C62ADD965E3D4746CC56.java in error:
      package drools.issues.P56;
      
      import static drools.issues.RulesB8F478785D3CFF51934B126DCB0906E0.*;
      import drools.issues.*;
      import org.drools.modelcompiler.dsl.pattern.D;
      
      @org.drools.compiler.kie.builder.MaterializedLambda()
      public enum LambdaConsequence56D5C9B4A166C62ADD965E3D4746CC56 implements org.drools.model.functions.Block3<org.drools.model.Drools, drools.issues.model.vehicles.ElectricCar, drools.issues.model.RegardsManager>, org.drools.model.functions.HashedExpression {
      
          INSTANCE;
      
          public static final String EXPRESSION_HASH = "73EB858AA97EF361030B94C86DFB98FD";
      
          public java.lang.String getExpressionHash() {
              return EXPRESSION_HASH;
          }
      
          @Override()
          public void execute(org.drools.model.Drools drools, drools.issues.model.vehicles.ElectricCar $v, drools.issues.model.RegardsManager regardsManager) throws java.lang.Exception {
              drools.insert(regardsManager.requestSendRegards("Hi, owner of a Tesla!").withParam("score", ((java.lang.String) $v.getScore())));
          }
      }
      ]
      ---
      Warning Messages:
      ---
      Info Messages:
      
      

              rhn-support-tkobayas Toshiya Kobayashi
              flozano@gmail.com Francisco Alejandro Lozano López
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: