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