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

JavaDialectConfiguration.LANGUAGE_LEVELS being strings causes binary search to not properly locate version 9

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • 7.33.0.Final
    • None
    • None
    • 2020 Week 10-12 (from Mar 2)
    • Hide
      1. Create new drools project in eclipse
      2. Select second option (Create a project and populate it with some example files)
      3. Build project using maven
      4. Only necessary to add a sample HelloWorld rule file to the project
      5. In the pom file, in case <runtime.version> is something other than 7.33.0.Final, change it to 7.33.0.Final
      6. Running the main "DroolsTest" should immediately throw the exception
      Show
      Create new drools project in eclipse Select second option (Create a project and populate it with some example files) Build project using maven Only necessary to add a sample HelloWorld rule file to the project In the pom file, in case <runtime.version> is something other than 7.33.0.Final, change it to 7.33.0.Final Running the main "DroolsTest" should immediately throw the exception
    • Low
    • NEW
    • NEW

      When i created a simple drools project (version 7.33.0.final) in eclipse (plugin version 7.32.0 final), i ran into the following error.
      (Note: drools file didn't specify "dialect java")

      java.lang.RuntimeException: Unable to load dialect 'org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration:java:org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration'
      	at org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl.addDialect(KnowledgeBuilderConfigurationImpl.java:405)
      	at org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl.buildDialectConfigurationMap(KnowledgeBuilderConfigurationImpl.java:391)
      	at org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl.init(KnowledgeBuilderConfigurationImpl.java:239)
      	at org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl.init(KnowledgeBuilderConfigurationImpl.java:191)
      	at org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl.<init>(KnowledgeBuilderConfigurationImpl.java:159)
      	at org.drools.compiler.kie.builder.impl.AbstractKieProject.getBuilderConfiguration(AbstractKieProject.java:302)
      	at org.drools.compiler.kie.builder.impl.AbstractKieProject.createKnowledgeBuilder(AbstractKieProject.java:288)
      	at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:213)
      	at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:75)
      	at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:274)
      	at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:242)
      	at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:192)
      	at com.sample.RunnableTest.createKieBase(RunnableTest.java:67)
      	at com.sample.RunnableTest.run(RunnableTest.java:36)
      	at java.base/java.lang.Thread.run(Thread.java:844)
      Caused by: java.lang.RuntimeException: value '9' is not a valid language level
      	at org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration.setJavaLanguageLevel(JavaDialectConfiguration.java:102)
      	at org.drools.compiler.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:80)
      	at org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl.addDialect(KnowledgeBuilderConfigurationImpl.java:401)
      	... 14 more
      

      Once debugged, i saw that the "LANGUAGE_LEVEL" array in "JavaDialectConfiguration" stores the java versions as strings, and in the method that throws the exception "setJavaLanguageLevel", it uses binary search to locate the version from that array.
      The problem with this is that it compares them lexicographically, so java version 9 would be greater than versions 10, 11 and 12.

      So, out of the array

      {"1.5", "1.6", "1.7", "1.8", "9", "10", "11", "12"}

      , to find 9, the following values are tried out:

      1. Start: low=0, high=7
      2. Middle (index 3) is 1.8, smaller than 9, move middle to 10, low=4(mid + 1), high=7
      3. Middle (index 5) is 10, smaller than 9, move middle to 11, low=6(mid + 1), high=7
      4. Middle (index 6) is 11, smaller than 9, move middle to 12, low=7(mid + 1), high=7
      5. Middle is 12, smaller than 9, low > high, end search

      The fix would be simple enough, either they should be sorted (lexicographically), or they should be floats.

      My default workspace jre is 9.0.1.

              mfusco@redhat.com Mario Fusco
              natanasov Nikola Atanasov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Estimated:
                  Original Estimate - 1 hour
                  1h
                  Remaining:
                  Remaining Estimate - 1 hour
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified