Uploaded image for project: 'Beehive'
  1. Beehive
  2. BEEHIVE-1059

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0, 1.0.1, 1.0.2
    • 1.0.2
    • NetUI
    • None

    Description

      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" ); }

      Attachments

        1. j1059-repro.zip
          3 kB
          Howard Carlin Rogers

        Activity

          People

            jzhuo Julie Zhuo
            crogers Howard Carlin Rogers
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: