Issue Details (XML | Word | Printable)

Key: BEEHIVE-1059
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Julie Zhuo
Reporter: Carlin Rogers
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Beehive

ClassCastException when InternalUtils.addActionError() casts ActionMessages for the Global.ERROR_KEY attribute to a sub class, ActionErrors

Created: 04/Feb/06 07:13 AM   Updated: 26/Jun/07 03:38 PM
Return to search
Component/s: NetUI
Affects Version/s: 1.0, 1.0.1, 1.0.2
Fix Version/s: 1.0.2

Time Tracking:
Not Specified

File Attachments:
  Size
Zip Archive Licensed for inclusion in ASF works j1059-repro.zip 2006-02-04 07:40 AM Carlin Rogers 3 kB

Resolution Date: 19/Feb/06 04:18 AM


 Description  « Hide
The implementaion of InternalUtils.addActionError() casts the org.apache.struts.action.ActionMessages for the Global.ERROR_KEY attribute to a sub class of org.apache.struts.action.ActionErrors. However, in all the other code paths where we set the attribute for Global.ERROR_KEY, we use the parent class, ActionMessages.

If a user implements @Jpf.ExceptionHandler method in a page flow and then calls FlowController.addActionError(), they will experience this ClassCastException. When an exception is thrown, the DefaultExceptionsHandler will set the attribute for Global.ERROR_KEY with a new instance ActionMessages that includes the ActionMessage with the exception message. Then it invokes the exception handler declared in the annotations of the page flow. When the FlowController.addActionError() is called, the internal code path will call InternalUtils.addActionError() and try to cast the ActionMessages to ActionErrors, giving a stack trace like this...

03 Feb 2006 14:55:19,987 ERROR DefaultExceptionsHandler []: Unhandled Page Flow Exception

Throwable: java.lang.ClassCastException: org.apache.struts.action.ActionMessages

Stack Trace:
java.lang.ClassCastException: org.apache.struts.action.ActionMessages
        at org.apache.beehive.netui.pageflow.internal.InternalUtils.addActionError(InternalUtils.java:415)
        at org.apache.beehive.netui.pageflow.FlowController.addActionError(FlowController.java:1439)
...

I will add a test to this shortly. To reproduce you really just need an implementation of an exception handler that calls addActionError(). Something like this...

    @Jpf.ExceptionHandler(
        forwards = {
            @Jpf.Forward(
                name = "handleError",
                path = "index.jsp")
        })
    protected Forward bogusExceptionHandler( Controller.BogusException ex,
                                           String actionName,
                                           String message, Object form ) {
        Object[] args = ex.getMessageArgs();
        addActionError("name", "messageKey_2", args);
        return new Forward( "handleError" );
    }


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Carlin Rogers added a comment - 04/Feb/06 07:40 AM
This zip file includes a simple test to repro this issue. It can also be used as a test for the future.

Carlin Rogers added a comment - 04/Feb/06 07:46 AM
The fix for this bug is a two liner... famous last words. Once v1.0.1 is out the door and the flood gates open, I'll check this into the trunk.

In src/pageflow/org/apache/beehive/netui/pageflow/internal/InternalUtils, look for the method addActionError() and change...

    ActionErrors errors = ( ActionErrors ) request.getAttribute( Globals.ERROR_KEY );
    if ( errors == null ) request.setAttribute( Globals.ERROR_KEY, errors = new ActionErrors() );

to...

    ActionMessages errors = ( ActionMessages ) request.getAttribute( Globals.ERROR_KEY );
    if ( errors == null ) request.setAttribute( Globals.ERROR_KEY, errors = new ActionMessages() );

Carlin Rogers added a comment - 19/Feb/06 04:18 AM
Fixed with revision 378760. See http://svn.apache.org/viewcvs?rev=378760&view=rev

A test to cover this scenario was added to the BVT.

Russ Baker added a comment - 26/Jun/07 03:30 PM
Verified that Jpf.ExceptionHandler does not throw a ClassCastException when using the 'FlowController.addActionError()' method in the implementation of the ExceptionHandler. Verified using Carlin's attached repro against SVN 549584. I recommend that this bug be closed.

Julie Zhuo added a comment - 26/Jun/07 03:38 PM
Based on Russ's verification, close this out.