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