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

Overloaded method resolution is different between mvel and executable model (varargs)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Major
    • None
    • 7.73.0.Final
    • None
    • 2022 Week 41-43 (from Oct 10), 2022 Week 44-46 (from Oct 31), 2022 Week 47-49 (from Nov 21), 2022 Week 50-02 (from Dec 12)
    • 2
    • Hide

      See project https://github.com/flozano/drools-issues, class OverloadNumberMethodTest, test arrayOfIntToLongs

      ~/Projects/java/drools-issues  main took 2s ❯ ./gradlew test --tests OverloadNumberMethodTest
      To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.4.2/userguide/gradle_daemon.html#sec:disabling_the_daemon.
      Daemon will be stopped at the end of the build
      
      > Task :test FAILED
      
      OverloadNumberMethodTest > arrayOfIntToLongs(RuntimeType) > drools.issues.OverloadNumberMethodTest.arrayOfIntToLongs(RuntimeType)[2] FAILED
          drools.issues.executor.InvalidRulesException at OverloadNumberMethodTest.java:18
      
      2 tests completed, 1 failed
      
      FAILURE: Build failed with an exception.
      
      * What went wrong:
      Execution failed for task ':test'.
      > There were failing tests. See the report at: file:///Users/flozano/Projects/java/drools-issues/build/reports/tests/test/index.html
      
      * Try:
      > Run with --stacktrace option to get the stack trace.
      > Run with --info or --debug option to get more log output.
      > Run with --scan to get full insights.
      
      * Get more help at https://help.gradle.org
      
      BUILD FAILED in 4s
      4 actionable tasks: 4 executed
      
      Show
      See project https://github.com/flozano/drools-issues , class OverloadNumberMethodTest , test arrayOfIntToLongs ~/Projects/java/drools-issues  main took 2s ❯ ./gradlew test --tests OverloadNumberMethodTest To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.4.2/userguide/gradle_daemon.html#sec:disabling_the_daemon. Daemon will be stopped at the end of the build > Task :test FAILED OverloadNumberMethodTest > arrayOfIntToLongs(RuntimeType) > drools.issues.OverloadNumberMethodTest.arrayOfIntToLongs(RuntimeType)[2] FAILED drools.issues.executor.InvalidRulesException at OverloadNumberMethodTest.java:18 2 tests completed, 1 failed FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':test'. > There were failing tests. See the report at: file:///Users/flozano/Projects/java/drools-issues/build/reports/tests/test/index.html * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 4s 4 actionable tasks: 4 executed
    • Set a Value
    • NEW
    • NEW
    • ---
    • ---

    Description

      executable model fails to pass a vararg of ints to a vararg of longs, while mvel runtime happily accepted it.

      Given a fact of this class:

      public class Person {
      
      	private String firstName;
      // ...
      	private Collection<Long> favoriteNumbers = Collections.emptyList();
      // ...
      	public Collection<Long> getFavoriteNumbers() {
      		return favoriteNumbers;
      	}
      
      	public void setFavoriteNumbers(Collection<Long> favoriteNumbers) {
      		this.favoriteNumbers = favoriteNumbers;
      	}
      
      	public void setFavoriteNumbers(Long... values) {
      		this.favoriteNumbers = values == null ? null : Sets.newHashSet(values);
      	}
      
      	public void setFavoriteNumbers(String... values) {
      		this.favoriteNumbers = values == null ? null
      				: Sets.newHashSet(values).stream().map(Long::parseLong).collect(Collectors.toSet());
      	}
      
      

      this used to work with mvel, but doesn't work with executable model:

      rule "Pepe likes numbers with 7"
        when
          $p:drools.issues.model.Person(firstName=="Pepe")
        then
          $p.setFavoriteNumbers(7, 77, 777);
      end
      
      

      the compiler says The method setFavoriteNumbers(Collection<Long>) in the type Person is not applicable for the arguments (int, int, int) :

      [main] ERROR drools.issues.executor.DroolsInternalFactory - KieBuilder has errors (releaseId=drools.issues.rules:OverloadNumberMethodTest_arrayOfIntToLongs.drl:1.0.0): Error Messages:
      Message [id=1, level=ERROR, path=src/main/java/drools/issues/P88/LambdaConsequence88D6B1B3DC97FFECC8AFC0CC8E1D9584.java, line=20, column=707
         text=The method setFavoriteNumbers(Collection<Long>) in the type Person is not applicable for the arguments (int, int, int)]
      Message [id=2, level=ERROR, path=src/main/java/drools/issues/P88/LambdaConsequence88D6B1B3DC97FFECC8AFC0CC8E1D9584.java, line=0, column=0
         text=Java source of src/main/java/drools/issues/P88/LambdaConsequence88D6B1B3DC97FFECC8AFC0CC8E1D9584.java in error:
      package drools.issues.P88;
      
      import static drools.issues.Rules4F456B96750F7FA28227214602C7B5B9.*;
      import drools.issues.*;
      import org.drools.modelcompiler.dsl.pattern.D;
      
      @org.drools.compiler.kie.builder.MaterializedLambda()
      public enum LambdaConsequence88D6B1B3DC97FFECC8AFC0CC8E1D9584 implements org.drools.model.functions.Block1<drools.issues.model.Person>, org.drools.model.functions.HashedExpression {
      
          INSTANCE;
      
          public static final String EXPRESSION_HASH = "86924D0300A6A4EB4249BB413BE53BF9";
      
          public java.lang.String getExpressionHash() {
              return EXPRESSION_HASH;
          }
      
          @Override()
          public void execute(drools.issues.model.Person $p) throws java.lang.Exception {
              $p.setFavoriteNumbers(7, 77, 777);
          }
      }
      ]
      ---
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: