[rules-dev] NPE due to activation.getDeclarationValue( declId );

Wolfgang Laun wolfgang.laun at gmail.com
Fri Aug 6 08:40:19 EDT 2010


Assuming that this part of the API is meant to be used like this:

   List<String> declIds = );
   for( String declId: activation.getDeclarationIDs( ){
      Object declVal = activation.getDeclarationValue( declId );
      // ...
   }

I'm using this during ActivationEvent logging. If, however, a
fact is retracted, this code, when executed for an
AfterActivationFiredEvent, throws a NPE when declId is a
binding for a component of the retracted fact.

The optimum solution would be to not get such useless bindings
in the List<String> returned by getDeclarationIDs() which
is in AgendaItem.java. I have added the if-statement:

    public List<String> getDeclarationIDs() {
        Declaration[] declArray = this.getRule().getDeclarations();
        List<String> declarations = new ArrayList<String>();
        for( Declaration decl : declArray ) {
            // return only "sound" declaration IDs
            if( this.tuple.get( decl ).getObject() != null ){
                declarations.add( decl.getIdentifier() );
            }
        }
        return Collections.unmodifiableList( declarations );
    }

This is untested!
-W
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20100806/962ea47a/attachment.html 


More information about the rules-dev mailing list