1
votes

If I try a simple Drools rule with conditions on date type and uses conditional OR (||) I get the following error. If I change || to && it works fine. Is this a bug, known limitation or something wrong with my rule? I am using Drools 5.5.0 Final

Rule file

package net.madhura.drools.rules

import net.madhura.drools.DateContainer;

dialect "mvel"

rule "Test rule"
when
    $container: DateContainer(
        date >= "15-Oct-2013" || date <= "01-Oct-2013"
    )
then
    System.out.println("working");
end

DateContainer class

package net.madhura.drools;

import java.util.Date;

public class DateContainer {

    private Date date;

    public DateContainer(Date date) {
        this.date = date;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}

Errors

Unable to Analyse Expression date >= "15-Oct-2013" || date <= "01-Oct-2013":
[Error: Comparison operation requires compatible types. Found class java.util.Date and class java.lang.String]
[Near : {... date >= "15-Oct-2013" || date <= "01-Oct-2013" ....}]
                                              ^
[Line: 9, Column: 1] : [Rule name='Test rule']
1
The error says you cannot compare a Date and a String, nothing about the OR-operator. Have you tried the OR while you're comparing two Date instances?kaskelotti
@JAndy According to Drools documentation on dates (docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/…), dates can be compared like this. Besides, it works correctly if I change || to &&.Madhura Jayaratne
Yep, you're right. According to the docs, it should work.kaskelotti
Similar issue in the Drools issue tracker: issues.jboss.org/browse/JBRULES-3517 (supposed to be fixed though in 5.5.0, which you are already using; might be a regression?)Miichi

1 Answers

1
votes

Apparently this is a Drools bug which is now fixed. Bug report is here