Details
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)
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
- is related to
-
STR-2587 Enhancements for ActionRedirect
- Resolved