beehive-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chad Schoettger" <chad.schoett...@gmail.com>
Subject Re: servlet 2.5 api compat...
Date Fri, 28 Jul 2006 21:42:05 GMT
Actually its a bit more complicated,

ServletException has a method called 'getRootCause()', the java doc
for the constructor looks like:

ServletException(Throwable rootCause)

in the 2.4 api, creating a ServletException with this constructor results in:

getRootCause() == rootCause
getCause() == null

in the 2.5 api the same call results in:
getRootCause() == rootCause
getCause() == rootCause

if the following is done instead (with 2.5 api):

ServletException se = new ServletException();
se.initCause(rootCause);

then
getRootCause() == null
getCause() == rootCause


given this and performance considerations it would probably be best to
do something like:

ServletException se = new ServletException(rootCause);
if (se.getCause() == null) {
    se.initCause(rootCause);
}

Interestingly enough if you make a call to initCause(null) and then
call initCause() again you still get an IllegalStateException.  But
for the locations in the Beehive code it should be safe to check for
null since it is right after the exception was created.

Thanks for all the input on this one, I'll update my proposed change
accordingly.

 - Chad

On 7/28/06, Andrew McCulloch <amccullo@gmail.com> wrote:
> 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 <xibin.zeng@gmail.com> 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 <amccullo@gmail.com> 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 <chad.schoettger@gmail.com> 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
> > > >
> > >
> > >
> >
> >
>
>

Mime
View raw message