[jboss-jira] [JBoss JIRA] (JBRULES-3581) Couldn't anymore personalize comparison method starting from drools 5.4.0
Mario Fusco (JIRA)
jira-events at lists.jboss.org
Tue Jul 24 11:14:08 EDT 2012
[ https://issues.jboss.org/browse/JBRULES-3581?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12707571#comment-12707571 ]
Mario Fusco commented on JBRULES-3581:
--------------------------------------
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)
> Couldn't anymore personalize comparison method starting from drools 5.4.0
> -------------------------------------------------------------------------
>
> Key: JBRULES-3581
> URL: https://issues.jboss.org/browse/JBRULES-3581
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: drools-compiler
> Affects Versions: 5.4.0.Final
> Environment: JVM Hotspot 1.6.0_33 ; sbt 0.11.3 ; scala 2.9.2 ; Linux 3.2.1-gentoo-r2 ;
> Reporter: david crosson
> Assignee: Mario Fusco
>
> 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 {
> case Release(thatname) => NaturalSort.ord.compare(name, thatname)
> case thatname:String => NaturalSort.ord.compare(name, thatname)
> case _ => 1
> }
> }
> 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 : {... release < "2.6.18" ....}]
> ^ : [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)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list