Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-2499

Find required forward or throw exception

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 1.4.0
    • Core
    • None
    • Operating System: All
      Platform: All
    • 35361

    Description

      Currently, when mapping.findForward() is called in an Action, and the named
      forward is not found (because of a typo, or perhaps because it is dynamically
      determined incorrectly), Struts returns null, which resuls in a blank page,
      and no indication to the developer about what went wrong.

      Someone, I forget who (sorry!) recently added some code to log a message in
      such a case, but that was after 1.2.7 was cut. That would be a step in the
      right direction, but I believe still not optimal.

      My feeling, echoed by some on the mailing lists, is that an exception should
      be thrown. The thinking is that such a situation really shouldn't happen in a
      production application, it should generally be a development-time problem, and
      as such should be easier to track down. Also, it is pretty much a showstopper
      kind of problem, i.e., not something an app would expect to recover from. As
      such, an exeption is probably more appropriate than just a log message.

      I propose the following change be made... in the ActionMapping class, alter
      the findForward() method as follows:

      /**

      • <p>Find and return the <code>ForwardConfig</code> instance defining
      • how forwarding to the specified logical name should be handled. This is
      • performed by checking local and then global configurations for the
      • specified forwarding configuration. If no forwarding configuration
      • can be found, return <code>null</code>.</p>
        *
      • @param name Logical name of the forwarding instance to be returned
      • @throws IllegalStateException If the forward is not found
        */
        public ActionForward findForward(String name) throws IllegalStateException {

      ForwardConfig config = findForwardConfig(name);
      if (config == null)

      { config = getModuleConfig().findForwardConfig(name); }

      if (null == config)

      { throw new IllegalStateException("Forward not found: " + name); }

      return ((ActionForward) config);

      }

      Arguably there is a more appropriate exception type than
      IllegalStateException, and I have no problem if someone has a better
      suggestion. This is clearly a trivial change, but one I believe will make
      life easier on developers

      Attachments

        Issue Links

          Activity

            People

              pbenedict Paul Benedict
              fzammetti@omnytex.com Frank W. Zammetti
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: