-
Bug
-
Resolution: Won't Do
-
Major
-
None
-
5.4.0.Final
-
None
-
Compatibility/Configuration
I can't write anymore (since 5.4.0) straightforward rules such as :
rule "linux kernel too old"
when
s:LinuxServer(release < "2.6.18")
then
insert(new ConfWarning(s,
"Linux kernel is too old "+s.name))
end
where release is using Release type with a dedicated comparator :
case class Release(
name:String
) extends Ordered[AnyRef] {
override def compare(that:AnyRef) : Int = that match
}
I got the following error with the latest drools (it was ok with previous releases) :
[Error: Comparison operation requires compatible types. Found class com.orange.confxpert.model.Release and class java.lang.String]
I know that type enforcing is very important, but we should have a way to choose how strict must be type enforcements.
User experience is very important, saying release < "2.6.18" is quite more user friendly than saying release < Release.fromString("2.6.18"). This is an important issue, as rules may be written by non IT people.
[info] Running com.orange.confxpert.Main -a -r -v examples/xxxx/yyyyy
Unable to Analyse Expression release < "2.6.18":
[Error: Comparison operation requires compatible types. Found class xxxxx.model.Release and class java.lang.String]
[Near :
]
^ : [Rule name='linux kernel too old']
[error] (run-main) java.lang.IllegalArgumentException: Could not parse knowledge.
java.lang.IllegalArgumentException: Could not parse knowledge.
at org.drools.builder.impl.KnowledgeBuilderImpl.newKnowledgeBase(KnowledgeBuilderImpl.java:73)
at zzzzzz.Main$.analyze(Main.scala:66)
at zzzzzz..Main$$anonfun$main$1.apply(Main.scala:98)
at zzzzzz..Main$$anonfun$main$1.apply(Main.scala:96)
at scala.Option.map(Option.scala:133)
at zzzzzz..Main$.main(Main.scala:96)
at zzzzzz..Main.main(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
In Drools 5.4 we enforced a more strict type checking. Anyway you can override this behaviour for a specific class by declaring it non-typesafe as explained here: http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html/ch04.html#d0e4919
For example adding the following declaration to your DRL should work for you:
declare LinuxServer
@typesafe(false)
end
Also note that, in my opinion, that overridden comparison operator is not completely correct, at least under a semantic point of view, because it is not commutative, i.e. you cannot write a constraint like:
LinuxServer("2.6.18" >= release)