Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4463

Support propagating ognl errors other than NoSuchPropertyException

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.3.20
    • 7.0.0
    • Core Actions

    Description

      So, if you have a getter on an action that does some real work (say lazy load a list of cars from the database), and therefore might fail, it would be nice to have the option to have that propagate the exception, rather than be interpreted as if the property was not defined.

      The place that looks like this should be done is OgnlValueStack.setValue(). It takes throwExceptionOnFailure, but that is all or nothing. That ends up including XWorkExceptions with a root issue of ognl NoSuchPropertyException. These are frequent and not something we care about, at least in our code base. What I'd like to do is have some kind of parameterization that would let me turn on error propagation for not ognl property missing error. I did this locally, but it had to be super hacky because OgnlValueStack.setValue() is private. I basically installed my own ValueStackFactory that returned a copy of OgnlValueStack with the function changed to be like:

          /**
           * @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String)
           */
          public Object findValue(String expr, boolean throwExceptionOnFailure) {
              try {
                  setupExceptionOnFailure(throwExceptionOnFailure);
                  return tryFindValueWhenExpressionIsNotNull(expr);
              } catch (OgnlException e) {
                  return handleOgnlException(expr, throwExceptionOnFailure, e);
              } catch (XWorkException e) {
                  Throwable cause = e.getCause();
                  if (cause instanceof NoSuchPropertyException) {
                      return handleOtherException(expr, throwExceptionOnFailure, e);
                  }
                  return handleOtherException(expr, true, e);
              } catch (Exception e) {
                  return handleOtherException(expr, throwExceptionOnFailure, e);
              } finally {
                  ReflectionContextState.clear(context);
              }
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            perfnorm Jasper Rosenberg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: