Barney Barumba created DIGESTER-182:
---------------------------------------

             Summary: Popping the last object off the stack should update the 
root reference
                 Key: DIGESTER-182
                 URL: https://issues.apache.org/jira/browse/DIGESTER-182
             Project: Commons Digester
          Issue Type: Bug
    Affects Versions: 3.2
         Environment: Linux x_86_64, JDK 1.7.0_65
            Reporter: Barney Barumba


There is 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.

The attached patch fixes the digester to update the root reference when popping 
the last element fron the stack. It simply adds 4 lines to Digester.pop()
{code}
    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 );
        }
    }
{code}

Patch also contains a test case: {{DigesterTestCase.testStackActionGetRoot()}}.




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to