[ http://issues.apache.org/jira/browse/MYFACES-166?page=all ]
Martin Marinschek closed MYFACES-166:
-------------------------------------
Resolution: Fixed
Fix Version: Nightly Build
Thanks to Mathias Broekelman for the contribution
> exception handling in myfaces
> -----------------------------
>
> Key: MYFACES-166
> URL: http://issues.apache.org/jira/browse/MYFACES-166
> Project: MyFaces
> Type: Sub-task
> Versions: Nightly Build
> Reporter: Mathias Broekelmann
> Priority: Trivial
> Fix For: Nightly Build
>
> Exception handling in myfaces is strange.
> javax.faces.FacesServlet.logException(...) prints stacktrace through
> e.printStackTrace() and produces a large stacktrace.
> Calls to log.error(...) followed by a (re)thrown exception which was logged
> before dosn´t make sense. The decision how and when to log an exception
> should only be done if the exception can be handled and is not rethrown.
> MethodBindingImpl, PropertyResolverImpl, ValueBindingImpl also prints
> exception to log and rethrow them.
> I´ve added some patches which will reduce the stacktraces. That will make it
> easier for the user to find the cause of the exception.
> Index: FacesServlet.java
> ===================================================================
> RCS file:
> /home/cvspublic/incubator-myfaces/src/jsfapi/javax/faces/webapp/FacesServlet.java,v
> retrieving revision 1.12
> diff -u -r1.12 FacesServlet.java
> --- FacesServlet.java 13 Jul 2004 15:43:34 -0000 1.12
> +++ FacesServlet.java 5 Apr 2005 10:47:15 -0000
> @@ -162,7 +162,6 @@
> }
>
> _servletConfig.getServletContext().log(msg, e);
> - e.printStackTrace();
>
> Throwable cause = e.getCause();
> if (cause != null && cause != e)
> Index: MethodBindingImpl.java
> ===================================================================
> RCS file:
> /home/cvspublic/incubator-myfaces/src/myfaces/org/apache/myfaces/el/MethodBindingImpl.java,v
> retrieving revision 1.17
> diff -u -r1.17 MethodBindingImpl.java
> --- MethodBindingImpl.java 13 Oct 2004 11:51:00 -0000 1.17
> +++ MethodBindingImpl.java 5 Apr 2005 10:47:28 -0000
> @@ -159,25 +159,19 @@
> }
> else
> {
> - log.error("Exception while invoking expression "
> - + getExpressionString(), cause);
> - throw new EvaluationException("Expression: "
> + throw new EvaluationException("Exception while invoking
> expression "
> + getExpressionString(), cause);
> }
> }
> else
> {
> - log.error("Exception while invoking expression "
> - + getExpressionString(), e);
> - throw new EvaluationException("Expression: "
> + throw new EvaluationException("Exception while invoking
> expression "
> + getExpressionString(), e);
> }
> }
> - catch (Exception e)
> + catch (Throwable e)
> {
> - log.error("Exception while invoking expression "
> - + getExpressionString(), e);
> - throw new EvaluationException("Expression: "
> + throw new EvaluationException("Exception while invoking
> expression "
> + getExpressionString(), e);
> }
> }
> Index: PropertyResolverImpl.java
> ===================================================================
> RCS file:
> /home/cvspublic/incubator-myfaces/src/myfaces/org/apache/myfaces/el/PropertyResolverImpl.java,v
> retrieving revision 1.31
> diff -u -r1.31 PropertyResolverImpl.java
> --- PropertyResolverImpl.java 9 Jan 2005 18:15:12 -0000 1.31
> +++ PropertyResolverImpl.java 5 Apr 2005 10:47:39 -0000
> @@ -229,9 +229,8 @@
> }
> catch (RuntimeException e)
> {
> - log.error("Exception setting value of index " + index + " of
> bean "
> + throw new EvaluationException("Exception setting value of index
> " + index + " of bean "
> + base != null ? base.getClass().getName() : "NULL", e);
> - throw e;
> }
> }
>
> Index: ValueBindingImpl.java
> ===================================================================
> RCS file:
> /home/cvspublic/incubator-myfaces/src/myfaces/org/apache/myfaces/el/ValueBindingImpl.java,v
> retrieving revision 1.54
> diff -u -r1.54 ValueBindingImpl.java
> --- ValueBindingImpl.java 13 Oct 2004 11:51:00 -0000 1.54
> +++ ValueBindingImpl.java 5 Apr 2005 10:47:47 -0000
> @@ -353,21 +353,21 @@
> throw new PropertyNotFoundException(
> "Expression: '" + _expressionString + "'", e);
> }
> - catch (Exception e)
> + catch (Throwable e)
> {
> + String msg;
> if (newValue == null)
> {
> - log.error("Cannot set value for expression '"
> - + _expressionString + "' to null.", e);
> + msg = "Cannot set value for expression '"
> + + _expressionString + "' to null.";
> }
> else
> {
> - log.error("Cannot set value for expression '"
> + msg = "Cannot set value for expression '"
> + _expressionString + "' to a new value of type "
> - + newValue.getClass().getName(), e);
> + + newValue.getClass().getName();
> }
> - throw new EvaluationException(
> - "Expression: '" + _expressionString + "'", e);
> + throw new EvaluationException(msg, e);
> }
> }
>
> @@ -452,19 +452,9 @@
> throw new PropertyNotFoundException(
> "Expression: '" + _expressionString + "'", e);
> }
> - catch (Exception e)
> + catch(ELException e)
> {
> - log.error("Cannot get value for expression '" +
> _expressionString
> - + "'", e);
> -
> - if (e instanceof ELException)
> - {
> - log.error("Root cause for exception : ",
> - ((ELException) e).getRootCause());
> - }
> -
> - throw new EvaluationException(
> - "Expression: '" + _expressionString + "'", e);
> + throw new EvaluationException(e.getRootCause());
> }
> }
>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira