Thank you very much Wolfgang.
Then I understand that this composite restriction compiling error is fixed
in 5.2.0. Isn't it?
Thank you again for your time.
Kind regards,
Manuel Ortiz.
2011/12/22 Wolfgang Laun <wolfgang.laun(a)gmail.com>
>
> Sorry - I should have made it clear that it doesn't matter *why* one
> of the components of a composite restriction is in error. Either a
> missing declaration or a type incompatibility - it results in a null
> reference, and some agent processing this doesn't check.
>
> -W
>
> 2011/12/22 Manuel Ortiz <manuel.ortizramos(a)gmail.com>:
> > Dear Wolfgang:
> >
> > 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.
> >
> > I used "Hello world" example described at
> >
> >
> >
http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-expert/ht...
> >
> > 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.
> >
> > 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.
> >
> > Sorry for my english. I hope this explanation helps to understand the
> > bug.
> >
> > Kind regards,
> >
> > Manuel Ortiz.
> >
> > 2011/12/22 Wolfgang Laun <wolfgang.laun(a)gmail.com>
> >>
> >> Using an undeclared static variable (Message.HELLO) wasn't handled
> >> cleanly in 5.1.1. This has been fixed in 5.2.0.
> >> -W
> >>
> >>
> >> 2011/12/22 Manuel Ortiz <manuel.ortizramos(a)gmail.com>:
> >> > Dear Wolfgang:
> >> >
> >> > Just change the "Hello World" rule in the "Hello
World" example by
> >> > this
> >> > one...
> >> >
> >> > rule "Hello World"
> >> > when
> >> > m : Message( status == Message.HELLO || != "WrongType",
myMessage :
> >> > message
> >> > )
> >> > then
> >> > System.out.println( myMessage );
> >> > m.setMessage( "Goodbye cruel world" );
> >> > m.setStatus( Message.GOODBYE );
> >> > update( m );
> >> > end
> >> >
> >> > ...and you will get the following building error:
> >> >
> >> > Description Resource Path Location Type
> >> > Error: java.lang.NullPointerException Sample.drl
> >> > /DroolsTest2/src/main/rules
> >> > Unknown Drools Error
> >> >
> >> > This NullPointerException breaks the normal drools compiler execution
> >> > flow.
> >> > In contrast, if you use the following "Hello World" rule...
> >> >
> >> > rule "Hello World"
> >> > when
> >> > m : Message( status != "WrongType", myMessage : message )
> >> > then
> >> > System.out.println( myMessage );
> >> > m.setMessage( "Goodbye cruel world" );
> >> > m.setStatus( Message.GOODBYE );
> >> > update( m );
> >> > end
> >> >
> >> > ...then you get the following building errors:
> >> >
> >> > Description Resource Path Location Type
> >> > BuildError: Unable to create a Field value of type 'ValueType =
> >> > 'int''
> >> > and
> >> > value 'WrongType' Sample.drl /DroolsTest2/src/main/rules
Unknown
> >> > Drools
> >> > Error
> >> > BuildError: Unable to create restriction '[LiteralRestriction: !=
> >> > WrongType]' for field 'status' in the rule 'Hello
World' Sample.drl
> >> > /DroolsTest2/src/main/rules line 7 Drools Error
> >> >
> >> > which don't break the drools compiler execution flow.
> >> >
> >> > I think this one should be the right output for the first example.
> >> >
> >> > 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.
> >> >
> >> > At PatternBuilder.java, substitute createRestriction by...
> >> >
> >> > private Restriction createRestriction(final RuleBuildContext
> >> > context,
> >> > final Pattern pattern,
> >> > final FieldConstraintDescr
> >> > fieldConstraintDescr,
> >> > final
> >> > RestrictionConnectiveDescr
> >> > top,
> >> > final InternalReadAccessor
> >> > extractor) {
> >> > Restriction[] restrictions = new
> >> > Restriction[top.getRestrictions().size()];
> >> > int index = 0;
> >> >
> >> > for ( Iterator it = top.getRestrictions().iterator();
> >> > it.hasNext();
> >> > ) {
> >> > RestrictionDescr restrictionDescr = (RestrictionDescr)
> >> > it.next();
> >> >
> >> > if ( restrictionDescr instanceof
> >> > RestrictionConnectiveDescr
> >> > ) {
> >> > restrictions[index] = this.createRestriction(
> >> > context,
> >> >
> >> > pattern,
> >> >
> >> > fieldConstraintDescr,
> >> >
> >> > (RestrictionConnectiveDescr) restrictionDescr,
> >> >
> >> > extractor );
> >> >
> >> > } else {
> >> > restrictions[index] = buildRestriction( context,
> >> > pattern,
> >> > extractor,
> >> >
> >> > fieldConstraintDescr,
> >> >
> >> > restrictionDescr
> >> > );
> >> > if ( restrictions[index] == null ) {
> >> > context.getErrors().add( new DescrBuildError(
> >> > context.getParentDescr(),
> >> >
> >> > fieldConstraintDescr,
> >> >
> >> > null,
> >> >
> >> > "Unable to
> >> > create restriction '" + restrictionDescr.toString() +
"' for field '"
> >> > +
> >> > fieldConstraintDescr.getFieldName() + "' in the rule
'" +
> >> > context.getRule().getName() + "'" ) );
> >> > }
> >> > }
> >> >
> >> > if(restrictions[index] == null)
> >> > {
> >> > index = 0;
> >> > break;
> >> > }
> >> > else
> >> > {
> >> > index++;
> >> > }
> >> > }
> >> >
> >> > if(index == 0) {
> >> > return null;
> >> > } else if ( restrictions.length > 1 ) {
> >> > AbstractCompositeRestriction composite = null;
> >> > if ( top.getConnective() ==
> >> > RestrictionConnectiveDescr.AND )
> >> > {
> >> > composite = new AndCompositeRestriction( restrictions
> >> > );
> >> > } else if ( top.getConnective() ==
> >> > RestrictionConnectiveDescr.OR
> >> > ) {
> >> > composite = new OrCompositeRestriction( restrictions
> >> > );
> >> > } else {
> >> > context.getErrors().add( new DescrBuildError(
> >> > context.getParentDescr(),
> >> >
> >> > fieldConstraintDescr,
> >> > null,
> >> >
"This
> >> > is a
> >> > bug: Impossible to create a composite restriction for connective:
" +
> >> > top.getConnective() + "' for field '" +
> >> > fieldConstraintDescr.getFieldName()
> >> > + "' in the rule '"
> >> >
> >> > +
> >> > context.getRule().getName() + "'" ) );
> >> > }
> >> >
> >> > return composite;
> >> > } else if ( restrictions.length == 1 ) {
> >> > return restrictions[0];
> >> > }
> >> > context.getErrors().add( new DescrBuildError(
> >> > context.getParentDescr(),
> >> >
> >> > fieldConstraintDescr,
> >> > null,
> >> > "This is a
bug:
> >> > trying
> >> > to create a restriction for an empty restriction list for field
'" +
> >> > fieldConstraintDescr.getFieldName() + "' in the rule
'" +
> >> > context.getRule().getName() + "'" ) );
> >> > return null;
> >> > }
> >> >
> >> > Kind regards,
> >> >
> >> > Manuel Ortiz.
> >> >
> >> >
> >> > 2011/12/22 Wolfgang Laun <wolfgang.laun(a)gmail.com>
> >> >>
> >> >> Now would you mind posting an example reproducing this error...
> >> >> -W
> >> >>
> >> >> On 22/12/2011, Manuel Ortiz <manuel.ortizramos(a)gmail.com>
wrote:
> >> >> > Dear Sirs:
> >> >> >
> >> >> > I'm working on an application which writes a set of rules
using
> >> >> > information
> >> >> > which is stored in BDD tables. This information can be
'wrong'
> >> >> > concerning
> >> >> > rule compilation, and I expect that Drools reports the
> >> >> > corresponding
> >> >> > compilation errors.
> >> >> >
> >> >> > I've found that PatternBuilder.createRestriction() fails
to
> >> >> > process
> >> >> > composite restrictions when one of the single restrictions
cannot
> >> >> > be
> >> >> > implemented. The problem is that although one of the sigle
> >> >> > restrictions
> >> >> > is
> >> >> > returned null, the composite restriction array is succesfully
> >> >> > returned,
> >> >> > one
> >> >> > of its elements being null, wich causes a
NullPointerException
> >> >> > when
> >> >> > the
> >> >> > composite restriction is processed in
> >> >> > PatternBuilder.build(AbstractCompositeConstraint version) to
> >> >> > obtain a
> >> >> > MultiRestrictionFieldConstraint object.
> >> >> >
> >> >> > I would like to know if this bug has yet been reported and
fixed
> >> >> > in
> >> >> > some
> >> >> > Drools version beyond 5.1.1
> >> >> >
> >> >> > Thank you very much for your time.
> >> >> >
> >> >> > Kind regards,
> >> >> >
> >> >> > Manuel Ortiz
> >> >> >
> >> >> _______________________________________________
> >> >> rules-users mailing list
> >> >> rules-users(a)lists.jboss.org
> >> >>
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >> >
> >> >
> >> > _______________________________________________
> >> > rules-users mailing list
> >> > rules-users(a)lists.jboss.org
> >> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >>
https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/rules-users
> >
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users