Dear Wolfgang:<div><br></div><div>Sorry, I don'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 "Hello world" 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 "Hello World" example project and that this static variable shouldn'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"><<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">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>
<div class="HOEnZb"><div class="h5">> 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 : 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 /DroolsTest2/src/main/rules<br>
> Unknown Drools Error<br>
><br>
> This NullPointerException breaks the normal drools compiler execution 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'' 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 nor<br>
> simple) cannot be constructed.<br>
><br>
> At PatternBuilder.java, substitute createRestriction by...<br>
><br>
> private Restriction createRestriction(final RuleBuildContext context,<br>
> final Pattern pattern,<br>
> final FieldConstraintDescr<br>
> fieldConstraintDescr,<br>
> final 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(); it.hasNext();<br>
> ) {<br>
> RestrictionDescr restrictionDescr = (RestrictionDescr)<br>
> it.next();<br>
><br>
> if ( restrictionDescr instanceof RestrictionConnectiveDescr ) {<br>
> restrictions[index] = this.createRestriction( context,<br>
> pattern,<br>
><br>
> fieldConstraintDescr,<br>
><br>
> (RestrictionConnectiveDescr) restrictionDescr,<br>
> extractor );<br>
><br>
> } else {<br>
> restrictions[index] = buildRestriction( context,<br>
> pattern,<br>
> extractor,<br>
><br>
> fieldConstraintDescr,<br>
> restrictionDescr );<br>
> if ( restrictions[index] == null ) {<br>
> context.getErrors().add( new DescrBuildError(<br>
> context.getParentDescr(),<br>
><br>
> fieldConstraintDescr,<br>
> null,<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>
> composite = new AndCompositeRestriction( restrictions );<br>
> } else if ( top.getConnective() == 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 '" + 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>
> fieldConstraintDescr,<br>
> null,<br>
> "This is a bug: 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 restrictions<br>
>> > is<br>
>> > returned null, the composite restriction array is succesfully returned,<br>
>> > one<br>
>> > of its elements being null, wich causes a NullPointerException when 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 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>
</div></div></blockquote></div><br></div>