You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Barney <b0...@bsxl.com> on 2015/01/02 12:26:25 UTC

[digester] Should popping the last object off the stack update theroot?

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


Re: [digester] Should popping the last object off the stack update the root?

Posted by Benedikt Ritter <br...@apache.org>.
2015-01-02 21:29 GMT+01:00 Barney <b0...@bsxl.com>:

> Thanks Benedikt, I'll put a patch together and submit a JIRA.
>
> The main reason I didn't do that the first time was I wasn't sure if this
> idea had already been considered and rejected for some reason, so I thought
> I'd just check here first.


TBH there hasn't been a lot of activity in digester for some while now. But
maybe some new patches will raise new attention.

Benedikt


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


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: [digester] Should popping the last object off the stack update the root?

Posted by Barney <b0...@bsxl.com>.
Thanks Benedikt, I'll put a patch together and submit a JIRA.

The main reason I didn't do that the first time was I wasn't sure if 
this idea had already been considered and rejected for some reason, so I 
thought I'd just check here first.

Cheers,


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


Re: [digester] Should popping the last object off the stack update the root?

Posted by Benedikt Ritter <br...@apache.org>.
Hello Barney,

thanks for the report. The normal way for contributing code is by attaching
a patch to jira [1]. Don't forget to include some unit tests ;-)

TIA!
Benedikt

[1] https://issues.apache.org/jira

2015-01-02 12:26 GMT+01:00 Barney <b0...@bsxl.com>:

> 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
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter