struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jasper Rosenberg (JIRA)" <j...@apache.org>
Subject [jira] [Created] (WW-4463) Support propagating ognl errors other than NoSuchPropertyException
Date Fri, 13 Feb 2015 20:56:11 GMT
Jasper Rosenberg created WW-4463:
------------------------------------

             Summary: Support propagating ognl errors other than NoSuchPropertyException
                 Key: WW-4463
                 URL: https://issues.apache.org/jira/browse/WW-4463
             Project: Struts 2
          Issue Type: Improvement
          Components: Core Actions
    Affects Versions: 2.3.20
            Reporter: Jasper Rosenberg
            Priority: Minor


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:

{code:java}
    /**
     * @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);
        }
    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message