DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23005>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23005

html:messages tag does not gracefully handle missing message resource keys.

           Summary: html:messages tag does not gracefully handle missing
                    message resource keys.
           Product: Struts
           Version: 1.1 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Custom Tags
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


In class org.apache.struts.taglib.html.MessagesTag the doAfterBody() method 
does not "gracefully" handle missing message resource keys. However, it does 
handle it in the doStartTag() method.

Namely:

----------
public int doStartTag() throws JspException {

...

        ActionMessage report = (ActionMessage) this.iterator.next();
        String msg =
            RequestUtils.message(
                pageContext,
                bundle,
                locale,
                report.getKey(),
                report.getValues());

        if (msg != null) {
            pageContext.setAttribute(id, msg);
        } else {
            pageContext.removeAttribute(id);

            // log missing key to ease debugging
            if (log.isDebugEnabled()) {
                log.debug(
                    messageResources.getMessage(
                        "messageTag.resources",
                        report.getKey()));
            }
        }
...

}
-----

Here a missing message resource key is handled i.e. if msg == null a log 
message is raised and the pageContext variable is not set.

However in doAfterBody():

-----

public int doAfterBody() throws JspException {

...

        // Decide whether to iterate or quit
        if (iterator.hasNext()) {
               ActionMessage report = (ActionMessage)iterator.next();
               String msg = RequestUtils.message(pageContext, bundle,
                                                 locale, report.getKey(),
                                                 report.getValues());

           pageContext.setAttribute(id, msg);

           return (EVAL_BODY_TAG);

...

}

----

Here, if the message resource key is not found then msg will be null and this 
statement: 

pageContext.setAttribute(id, msg);  

will cause a NullPointerException that will cause the page not to render.

I think it would be better that this method behave the same as doStartTag()

Best regards

James

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to