If generating and catching the IllegalStateException is a concern you could change
ServletException se = new ServletException(e); se.initCause(e); to ServletException se = new ServletException(); se.initCause(e); which should work the same in both 2.4 and 2.5. Unless there is some other side-effect of passing the cause to the constructor that I am missing. I guess there are many ways to accomplish both 2.4 and 2.5 compatibility Is the missing call to initCause in the ServletException constructor for version 2.4 a bug? It seems that by not calling initCause this would violate the api docs for Throwable. --Andrew On 7/28/06, Xibin Zeng <[EMAIL PROTECTED]> wrote:
What about calling setCause() only when getCause() returns null? The only reason for my suggestion is trying to avoid generating and catching of the IllegalStateException. On 7/28/06, Andrew McCulloch <[EMAIL PROTECTED]> wrote: > > Chad, > > This seems like the right choice. The Throws clause in the api docs for > Throwable#initCause (J2SE 1.5) says ... > "IllegalStateException< > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/IllegalStateException.html > >- > if this throwable was created with > Throwable(Throwable)< > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#Throwable%28java.lang.Throwable%29 > >or > Throwable(String,Throwable)< > http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#Throwable%28java.lang.String,%20java.lang.Throwable%29 > >, > or this method has already been called on this throwable.". I think the > change you are suggesting handles both of these cases correctly. > > --Andrew > > On 7/28/06, Chad Schoettger <[EMAIL PROTECTED]> wrote: > > > > I've been playing around a bit with the 2.5 servlet api and Beehive, > > just to get a feel for what has changed. There isn't really all that > > much that causes issues for Beehive at runtime, the only thing I have > > found so far has been a difference in how ServletException and > > JspException work in 2.5. > > > > in the 2.4 servlet api, when you create a new ServletException: > > > > ServletException se = new ServletException(throwable); > > > > the ServletException superclass Throwable does not get its 'initCause' > > method invoked. > > > > > > In the 2.5 servlet api, it does. There is code in Beehive which does > > the following: > > > > ServletException se = new ServletException(e); > > se.initCause(e); > > > > The second line causes an IllegalStateException in the servlet 2.5 api > > since the cause has already been set via the constructor. The same is > > true for the JspException class. > > > > Does anyone have an issue with me updating the affected Beehive > > classes to correctly handle this case? The change would consist of: > > > > ServletException se = new ServletException(e); > > try { > > se.initCause(e); > > } catch (IllegalStateException ise) { > > // do nothing, just means 2.5 servlet api is being used. > > } > > > > At this point I'm not proposing we update the servlet api included in > > the <beehive>/servlet/external directory to a 2.5 implementation, just > > that we handle this case correctly for those users who may be > > interested in running beehive on a server which has the 2.5 api. > > > > The following classes would need to be modified: > > > > > > > <beehive>/trunk/netui/src/util/org/apache/beehive/netui/internal/ServletUtils > > > > > <beehive>/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/ConfigurePager > > > > > <beehive>/trunk/netui/src/tags-htmll/org/apache/beehive/netui/tags/AbstractSimpleTag > > > > > <beehive>/trunk/netui/src/tags-htmll/org/apache/beehive/netui/tags/ErrorHandling > > > > > <beehive>/trunk/netui/src/tags-htmll/org/apache/beehive/netui/tags/HtmlUtils > > > > > <beehive>/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/Attribute > > > > > <beehive>/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/IncludeSection > > > > > <beehive>/trunk/netui/src/tags-template/org/apache/beehive/netui/tags/template/Template > > > > > > > > - Thanks, Chad > > > >
