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