[rules-users] xml parsing bug

Paul Alexandrow paul at alexandrow.org
Mon Jun 30 16:25:54 EDT 2008


Hi,

this is a repost, and I'm sorry if I annoy anybody with it, but it's 
already a week and nobody replied yet (to what I think might be a 
serious issue for anybody using XML for configuration).
Or might this be an issue for the developers list rather than this list 
and should i post it there?

So here's again, what I have problems with:

I've encountered some strange behaviour (bug?) in Drools (4.0.7) when
adding packages from XML. Take the following rule as an example:

<rule name="constraintTest">
    <lhs>
       <pattern identifier="$foo" object-type="Bar" >
          <field-constraint field-name="a">
             <literal-restriction evaluator="==" value="A" />
          </field-constraint>
          <or-constraint-connective>
             <and-constraint-connective>
                <field-constraint field-name="b">
                   <literal-restriction evaluator="==" value="B" />
                </field-constraint>
                <field-constraint field-name="c">
                   <literal-restriction evaluator="==" value="C" />
                </field-constraint>
             </and-constraint-connective>
             <field-constraint field-name="d">
                <literal-restriction evaluator="==" value="D" />
             </field-constraint>
          </or-constraint-connective>
       </pattern>
    </lhs>
    <rhs>
       log("constraintTest");
    </rhs>
</rule>

Trying to add a package from this gives the following Error:

org.drools.compiler.DroolsParserException:
org.xml.sax.SAXParseException: <or-constraint-connective> is after an
invalid element: org.drools.xml.Handler
     at
org.drools.compiler.PackageBuilder.addPackageFromXml(PackageBuilder.java:184) 



Now here's what's strange: If you rewrite the pattern like this

<pattern identifier="$foo" object-type="Bar" >
    <or-constraint-connective>
       <and-constraint-connective>
          <field-constraint field-name="b">
             <literal-restriction evaluator="==" value="B" />
          </field-constraint>
          <field-constraint field-name="c">
             <literal-restriction evaluator="==" value="C" />
          </field-constraint>
       </and-constraint-connective>
       <field-constraint field-name="d">
          <literal-restriction evaluator="==" value="D" />
       </field-constraint>
    </or-constraint-connective>
    <field-constraint field-name="a">
       <literal-restriction evaluator="==" value="A" />
    </field-constraint>
</pattern>

in other words (and I tried this with a couple of variations), if you
put all field-constraints after any and-constraint-connectives or
or-constraint-connectives sharing the same parent element, the package
adds just fine.

I couldn't find any reason, why this should be intended behaviour, so I
assume it's a bug.
I took a little peek into Drools' source, and my guess is, that there's
just some 'validPeers' missing in one of the *Handler classes that are
responsible for the validation of Drools XML configuration files.
However, this really is just my first guess.

'Adds just fine' is not the whole truth though: Modifying the pattern as
  described above, still leaves me with the following message (strangely
printed to stdout, instead of using a logger or throwing an exception):

(null: 33, 46): cvc-complex-type.2.4.a: Invalid content starting with
element 'field-constraint'. One of
'{"http://drools.org/drools-4.0":and-constraint-connective}' is expected.

Now, if I wrap the "d" field-constraint (see my example) into an
and-constraint-connective (and thus being the field-constraint the only
element in the and-constraint-connective, which looks rather useless),
that message goes away.
Even more oddness: the "a" field-constraint doesn't cause such a message
- even without a wrapping it into an and-constraint-connective.

Many thanks in advance,
Paul

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080630/50592882/attachment.bin 


More information about the rules-users mailing list