Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:49:29+00:00 2026-06-07T04:49:29+00:00

Is there any way to let Drools handle a String, Integer comparison without having

  • 0

Is there any way to let Drools handle a String, Integer comparison without having to manually do type conversions?

I am having trouble comparing a string to an integer in a rule. The rule can be simplified to the following where fields is just a Map<String, String>.

rule "Test Rule"
    when
        MapTest(fields["a"] != null, fields["a"] == 10)
    then
        System.out.println( "test succeeded" );
end

The problem is that given this rule, even when a = “10”, the consequence is never fired. According to the documentation at section 4.8.3.3.3 “Coercion is always in favor of the field type and not the value type”. So this rule seems like the 10 should be coerced to “10” and then this comparison should return true, but it doesn’t.

If a change the 10 to “10” the rule succeeds. Also if I do Integer.parseInt(fields[“a”]) the rule succeeds.

The more interesting part is if I change the operator to > or < and change the value of fields[“a”] appropriately the rule still succeeds! Is this because > and < aren’t technically valid operators on Strings so the two operands are converted to numeric values and compared?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:49:32+00:00Added an answer on June 7, 2026 at 4:49 am

    Drools appears to handle type coercion differently between versions 5.3 and 5.4. Wolfgang gave a good example of the differences on the Drools User Forum.

    To me this seems like a bug in version 5.3 because the documentation says coercion should be attempted but according to the example it is not (or at least it is not done properly). In the end I still do not know how the > and < operators work but at least I gathered enough information to know I have to parse the string to a numeric value in my case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's imagine I have instantiated generic type by Activator.CreateInstance. Is there any way to
Is there any way to let user pick color from screen ? Like the
Is there any way to check step by step what's going on in let's
Is there any way to have a default MessageBox.Show() caption? Let says I would
Is there any way to get mouse position relative to it's parent element? Let's
Is there any way to make extension to pop up when event occurs? Let's
Is there any way to get PDF document text language? Example: Let's say I
Let's say I have 10 threads running simultaneously. Is there any way of calling
Let's say you have var funct=function(a,b){ return a+b; }; console.log(funct); Is there any way
Is there any way to let FindBugs check and warn me if a CheckForNull

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.