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

RequestUtils lookup does not throw an exception when bean not found but property is null

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0 Beta 3
    • 1.0.0
    • Tag Libraries
    • None
    • Operating System: other
      Platform: Other
    • 2088

    Description

      In org.apache.struts.util.RequestUtils, look at the following method:

      public static Object lookup(PageContext pageContext, String name,
      String property, String scope)
      throws JspException {

      Given the code:
      1: Object bean = lookup(pageContext, name, scope);
      2: if (property == null)
      3: return (bean);
      4: if (bean == null)

      { 5: JspException e = new JspException 6: (messages.getMessage("lookup.bean", name, scope)); 7: saveException(pageContext, e); 8: throw e; 9: }

      Line 1: bean can legitimately be null from the return from lookup, if the bean
      was not found, and the scope was null or a proper scope name. If property is
      also null, this method returns null instead of throwing an exception.

      According to the javadoc comments of this method,

      • @exception JspException if the specified bean is not found

      this coded behavior is not correct, and an exception should be thrown whenever
      bean is null.

      The fix is simple, just change around the order of the code:

      4: if (bean == null)

      { 5: JspException e = new JspException 6: (messages.getMessage("lookup.bean", name, scope)); 7: saveException(pageContext, e); 8: throw e; 9: }

      2: if (property == null)
      3: return (bean);

      By checking for the property after checking if the bean is null, the documented
      behavior should occur.

      Attachments

        Activity

          People

            craigmcc Craig R. McClanahan
            scott@arondight.com scott
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: