commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barney <b002...@bsxl.com>
Subject [digester] Should popping the last object off the stack update the root?
Date Fri, 02 Jan 2015 11:26:25 GMT
Hi,

There seems to me to be a bit of a discrepancy between the way push() 
and pop() interact with the root object when stack actions are used to 
change the object.

* If a stack action changes the root object when being pushed onto the 
stack then the root reference is set to the changed object.
* If a stack action changes the root object when being popped from the 
stack then the root reference is not updated.

I'm not sure if this is intended behaviour or not, but it caught me out 
when trying to use stack actions for a specific problem, as I expected 
digester.parse() to return the value from stackAction.onPop(). I solved 
my specific problem a different way so this no longer affects me, but 
thought I'd ask anyway.

So should Digester.pop() be updated to do this?

     public <T> T pop()
     {
         try
         {
             T popped = this.<T> npeSafeCast( stack.pop() );
             if ( stackAction != null )
             {
                 popped = stackAction.onPop( this, null, popped );
             }
++          if ( stack.size() == 0 )
++          {
++              root = popped;
++          }
             return popped;
         }
         catch ( EmptyStackException e )
         {
             log.warn( "Empty stack (returning null)" );
             return ( null );
         }
     }

Cheers,

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message