Thank you very much Wolfgang.<div><br></div><div>Then I understand that this composite restriction compiling error is fixed in 5.2.0. Isn&#39;t it?</div><div><br></div><div>Thank you again for your time.</div><div><br></div>
<div>Kind regards,</div><div><br></div><div>Manuel Ortiz.<br><br><div class="gmail_quote">2011/12/22 Wolfgang Laun <span dir="ltr">&lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Sorry - I should have made it clear that it doesn&#39;t matter *why* one<br>
of the components of a composite restriction is in error. Either a<br>
missing declaration or a type incompatibility - it results in a null<br>
reference, and some agent processing this doesn&#39;t check.<br>
<div class="HOEnZb"><div class="h5"><br>
-W<br>
<br>
2011/12/22 Manuel Ortiz &lt;<a href="mailto:manuel.ortizramos@gmail.com">manuel.ortizramos@gmail.com</a>&gt;:<br>
&gt; Dear Wolfgang:<br>
&gt;<br>
&gt; Sorry, I don&#39;t understand your answer very well. The bug I report has to do<br>
&gt; with composite restrictions, not with static variable declarations. Maybe my<br>
&gt; bug description is not very good.<br>
&gt;<br>
&gt; I used &quot;Hello world&quot; example described at<br>
&gt;<br>
&gt; <a href="http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-expert/html/ch08.html#d0e6981" target="_blank">http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-expert/html/ch08.html#d0e6981</a><br>

&gt;<br>
&gt; changing the first single restriction to a composite restriction in which<br>
&gt; the second part of the restriction compares an int to a string literal to<br>
&gt; fire a wrong type rule compile error. But as this second restriction belongs<br>
&gt; to a composite restriction, the composite one is created with a null<br>
&gt; component, no compile error reported.<br>
&gt;<br>
&gt; I understand that Message.HELLO is correctly declared in the &quot;Hello World&quot;<br>
&gt; example project and that this static variable shouldn&#39;t be a problem at<br>
&gt; compiling. In fact, if you change the static variable by a literal number,<br>
&gt; the error would be the same.<br>
&gt;<br>
&gt; Sorry for my english. I hope this explanation helps to understand the bug.<br>
&gt;<br>
&gt; Kind regards,<br>
&gt;<br>
&gt; Manuel Ortiz.<br>
&gt;<br>
&gt; 2011/12/22 Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt;<br>
&gt;&gt; Using an undeclared static variable (Message.HELLO) wasn&#39;t handled<br>
&gt;&gt; cleanly in 5.1.1. This has been fixed in 5.2.0.<br>
&gt;&gt; -W<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; 2011/12/22 Manuel Ortiz &lt;<a href="mailto:manuel.ortizramos@gmail.com">manuel.ortizramos@gmail.com</a>&gt;:<br>
&gt;&gt; &gt; Dear Wolfgang:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Just change the &quot;Hello World&quot; rule in the &quot;Hello World&quot; example by this<br>
&gt;&gt; &gt; one...<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; rule &quot;Hello World&quot;<br>
&gt;&gt; &gt; when<br>
&gt;&gt; &gt; m : Message( status == Message.HELLO || != &quot;WrongType&quot;, myMessage :<br>
&gt;&gt; &gt; message<br>
&gt;&gt; &gt; )<br>
&gt;&gt; &gt; then<br>
&gt;&gt; &gt; System.out.println( myMessage );<br>
&gt;&gt; &gt; m.setMessage( &quot;Goodbye cruel world&quot; );<br>
&gt;&gt; &gt; m.setStatus( Message.GOODBYE );<br>
&gt;&gt; &gt; update( m );<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ...and you will get the following building error:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Description Resource Path Location Type<br>
&gt;&gt; &gt; Error: java.lang.NullPointerException Sample.drl<br>
&gt;&gt; &gt; /DroolsTest2/src/main/rules<br>
&gt;&gt; &gt; Unknown Drools Error<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; This NullPointerException breaks the normal drools compiler execution<br>
&gt;&gt; &gt; flow.<br>
&gt;&gt; &gt; In contrast, if you use the following &quot;Hello World&quot; rule...<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; rule &quot;Hello World&quot;<br>
&gt;&gt; &gt; when<br>
&gt;&gt; &gt; m : Message( status != &quot;WrongType&quot;, myMessage : message )<br>
&gt;&gt; &gt; then<br>
&gt;&gt; &gt; System.out.println( myMessage );<br>
&gt;&gt; &gt; m.setMessage( &quot;Goodbye cruel world&quot; );<br>
&gt;&gt; &gt; m.setStatus( Message.GOODBYE );<br>
&gt;&gt; &gt; update( m );<br>
&gt;&gt; &gt; end<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; ...then you get the following building errors:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Description Resource Path Location Type<br>
&gt;&gt; &gt; BuildError: Unable to create a Field value of type  &#39;ValueType = &#39;int&#39;&#39;<br>
&gt;&gt; &gt; and<br>
&gt;&gt; &gt; value &#39;WrongType&#39; Sample.drl /DroolsTest2/src/main/rules Unknown Drools<br>
&gt;&gt; &gt; Error<br>
&gt;&gt; &gt; BuildError: Unable to create restriction &#39;[LiteralRestriction: !=<br>
&gt;&gt; &gt; WrongType]&#39; for field &#39;status&#39; in the rule &#39;Hello World&#39; Sample.drl<br>
&gt;&gt; &gt; /DroolsTest2/src/main/rules line 7 Drools Error<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; which don&#39;t break the drools compiler execution flow.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; I think this one should be the right output for the first example.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Below you can find my fix to this problem, based on the assumption that<br>
&gt;&gt; &gt; createRestriction must return null if the restriction (neither composite<br>
&gt;&gt; &gt; nor<br>
&gt;&gt; &gt; simple) cannot be constructed.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; At PatternBuilder.java, substitute createRestriction by...<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;     private Restriction createRestriction(final RuleBuildContext<br>
&gt;&gt; &gt; context,<br>
&gt;&gt; &gt;                                           final Pattern pattern,<br>
&gt;&gt; &gt;                                           final FieldConstraintDescr<br>
&gt;&gt; &gt; fieldConstraintDescr,<br>
&gt;&gt; &gt;                                           final<br>
&gt;&gt; &gt; RestrictionConnectiveDescr<br>
&gt;&gt; &gt; top,<br>
&gt;&gt; &gt;                                           final InternalReadAccessor<br>
&gt;&gt; &gt; extractor) {<br>
&gt;&gt; &gt;         Restriction[] restrictions = new<br>
&gt;&gt; &gt; Restriction[top.getRestrictions().size()];<br>
&gt;&gt; &gt;         int index = 0;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;         for ( Iterator it = top.getRestrictions().iterator();<br>
&gt;&gt; &gt; it.hasNext();<br>
&gt;&gt; &gt; ) {<br>
&gt;&gt; &gt;             RestrictionDescr restrictionDescr = (RestrictionDescr)<br>
&gt;&gt; &gt; it.next();<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;             if ( restrictionDescr instanceof RestrictionConnectiveDescr<br>
&gt;&gt; &gt; ) {<br>
&gt;&gt; &gt;                 restrictions[index] = this.createRestriction( context,<br>
&gt;&gt; &gt;                                                                 pattern,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; fieldConstraintDescr,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; (RestrictionConnectiveDescr) restrictionDescr,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; extractor );<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;             } else {<br>
&gt;&gt; &gt;                 restrictions[index] = buildRestriction( context,<br>
&gt;&gt; &gt;                                                         pattern,<br>
&gt;&gt; &gt;                                                         extractor,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; fieldConstraintDescr,<br>
&gt;&gt; &gt;                                                         restrictionDescr<br>
&gt;&gt; &gt; );<br>
&gt;&gt; &gt;                 if ( restrictions[index] == null ) {<br>
&gt;&gt; &gt;                     context.getErrors().add( new DescrBuildError(<br>
&gt;&gt; &gt; context.getParentDescr(),<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; fieldConstraintDescr,<br>
&gt;&gt; &gt;                                                                   null,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; &quot;Unable to<br>
&gt;&gt; &gt; create restriction &#39;&quot; + restrictionDescr.toString() + &quot;&#39; for field &#39;&quot; +<br>
&gt;&gt; &gt; fieldConstraintDescr.getFieldName() + &quot;&#39; in the rule &#39;&quot; +<br>
&gt;&gt; &gt; context.getRule().getName() + &quot;&#39;&quot; ) );<br>
&gt;&gt; &gt;                 }<br>
&gt;&gt; &gt;             }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;             if(restrictions[index] == null)<br>
&gt;&gt; &gt;             {<br>
&gt;&gt; &gt; index = 0;<br>
&gt;&gt; &gt; break;<br>
&gt;&gt; &gt;             }<br>
&gt;&gt; &gt;             else<br>
&gt;&gt; &gt;             {<br>
&gt;&gt; &gt; index++;<br>
&gt;&gt; &gt;             }<br>
&gt;&gt; &gt;         }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; if(index == 0) {<br>
&gt;&gt; &gt; return null;<br>
&gt;&gt; &gt;         } else if ( restrictions.length &gt; 1 ) {<br>
&gt;&gt; &gt;             AbstractCompositeRestriction composite = null;<br>
&gt;&gt; &gt;             if ( top.getConnective() == RestrictionConnectiveDescr.AND )<br>
&gt;&gt; &gt; {<br>
&gt;&gt; &gt;                 composite = new AndCompositeRestriction( restrictions );<br>
&gt;&gt; &gt;             } else if ( top.getConnective() ==<br>
&gt;&gt; &gt; RestrictionConnectiveDescr.OR<br>
&gt;&gt; &gt; ) {<br>
&gt;&gt; &gt;                 composite = new OrCompositeRestriction( restrictions );<br>
&gt;&gt; &gt;             } else {<br>
&gt;&gt; &gt;                 context.getErrors().add( new DescrBuildError(<br>
&gt;&gt; &gt; context.getParentDescr(),<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; fieldConstraintDescr,<br>
&gt;&gt; &gt;                                                               null,<br>
&gt;&gt; &gt;                                                               &quot;This is a<br>
&gt;&gt; &gt; bug: Impossible to create a composite restriction for connective: &quot; +<br>
&gt;&gt; &gt; top.getConnective() + &quot;&#39; for field &#39;&quot; +<br>
&gt;&gt; &gt; fieldConstraintDescr.getFieldName()<br>
&gt;&gt; &gt; + &quot;&#39; in the rule &#39;&quot;<br>
&gt;&gt; &gt;                                                                       +<br>
&gt;&gt; &gt; context.getRule().getName() + &quot;&#39;&quot; ) );<br>
&gt;&gt; &gt;             }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;             return composite;<br>
&gt;&gt; &gt;         } else if ( restrictions.length == 1 ) {<br>
&gt;&gt; &gt;             return restrictions[0];<br>
&gt;&gt; &gt;         }<br>
&gt;&gt; &gt;         context.getErrors().add( new DescrBuildError(<br>
&gt;&gt; &gt; context.getParentDescr(),<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; fieldConstraintDescr,<br>
&gt;&gt; &gt;                                                       null,<br>
&gt;&gt; &gt;                                                       &quot;This is a bug:<br>
&gt;&gt; &gt; trying<br>
&gt;&gt; &gt; to create a restriction for an empty restriction list for field &#39;&quot; +<br>
&gt;&gt; &gt; fieldConstraintDescr.getFieldName() + &quot;&#39; in the rule &#39;&quot; +<br>
&gt;&gt; &gt; context.getRule().getName() + &quot;&#39;&quot; ) );<br>
&gt;&gt; &gt;         return null;<br>
&gt;&gt; &gt;     }<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Kind regards,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Manuel Ortiz.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; 2011/12/22 Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Now would you mind posting an example reproducing this error...<br>
&gt;&gt; &gt;&gt; -W<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On 22/12/2011, Manuel Ortiz &lt;<a href="mailto:manuel.ortizramos@gmail.com">manuel.ortizramos@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt; Dear Sirs:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I&#39;m working on an application which writes a set of rules using<br>
&gt;&gt; &gt;&gt; &gt; information<br>
&gt;&gt; &gt;&gt; &gt; which is stored in BDD tables. This information can be &#39;wrong&#39;<br>
&gt;&gt; &gt;&gt; &gt; concerning<br>
&gt;&gt; &gt;&gt; &gt; rule compilation, and I expect that Drools reports the corresponding<br>
&gt;&gt; &gt;&gt; &gt; compilation errors.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I&#39;ve found that PatternBuilder.createRestriction() fails to process<br>
&gt;&gt; &gt;&gt; &gt; composite restrictions when one of the single restrictions cannot be<br>
&gt;&gt; &gt;&gt; &gt; implemented. The problem is that although one of the sigle<br>
&gt;&gt; &gt;&gt; &gt; restrictions<br>
&gt;&gt; &gt;&gt; &gt; is<br>
&gt;&gt; &gt;&gt; &gt; returned null, the composite restriction array is succesfully<br>
&gt;&gt; &gt;&gt; &gt; returned,<br>
&gt;&gt; &gt;&gt; &gt; one<br>
&gt;&gt; &gt;&gt; &gt; of its elements being null, wich causes a NullPointerException when<br>
&gt;&gt; &gt;&gt; &gt; the<br>
&gt;&gt; &gt;&gt; &gt; composite restriction is processed in<br>
&gt;&gt; &gt;&gt; &gt; PatternBuilder.build(AbstractCompositeConstraint version) to obtain a<br>
&gt;&gt; &gt;&gt; &gt; MultiRestrictionFieldConstraint object.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I would like to know if this bug has yet been reported and fixed in<br>
&gt;&gt; &gt;&gt; &gt; some<br>
&gt;&gt; &gt;&gt; &gt; Drools version beyond 5.1.1<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Thank you very much for your time.<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Kind regards,<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; Manuel Ortiz<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; rules-users mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; rules-users mailing list<br>
&gt;&gt; &gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; &gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br></div>