Updated Branches:
  refs/heads/wicket-1.5.x bdfc0f959 -> 7a4505889

WICKET-5146 call #destroy() when #init() fails, since the web container
will not do it

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7a450588
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7a450588
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7a450588

Branch: refs/heads/wicket-1.5.x
Commit: 7a45058892214a5a90a91dce52dc69fa05fdf669
Parents: bdfc0f9
Author: svenmeier <[email protected]>
Authored: Fri Apr 19 11:57:32 2013 +0200
Committer: svenmeier <[email protected]>
Committed: Fri Apr 19 11:57:32 2013 +0200

----------------------------------------------------------------------
 .../apache/wicket/protocol/http/WicketFilter.java  |   36 ++++++++++++---
 1 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/7a450588/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
index 3a3dc04..df94d64 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
@@ -96,8 +96,8 @@ public class WicketFilter implements Filter
        private boolean isServlet = false;
 
        /**
-        * default constructor, usually invoked through the servlet 
-        * container by the web.xml configuration
+        * default constructor, usually invoked through the servlet container 
by the web.xml
+        * configuration
         */
        public WicketFilter()
        {
@@ -106,11 +106,11 @@ public class WicketFilter implements Filter
        /**
         * constructor supporting programmatic setup of the filter
         * <p/>
-        *  this can be useful for programmatically creating and appending the 
-        *  wicket filter to the servlet context using servlet 3 features.
+        * this can be useful for programmatically creating and appending the 
wicket filter to the
+        * servlet context using servlet 3 features.
         * 
         * @param application
-        *           web application
+        *            web application
         */
        public WicketFilter(WebApplication application)
        {
@@ -385,6 +385,23 @@ public class WicketFilter implements Filter
                                ThreadContext.detach();
                        }
                }
+               catch (Exception e)
+               {
+                       // #destroy() might not be called by the web container 
when #init() fails,
+                       // so destroy now
+                       log.warn("initialization failed, destroying now");
+
+                       try
+                       {
+                               destroy();
+                       }
+                       catch (Exception destroyException)
+                       {
+                               log.warn("Unable to destroy after 
initialization failure", destroyException);
+                       }
+
+                       throw new ServletException(e);
+               }
                finally
                {
                        if (newClassLoader != previousClassLoader)
@@ -521,7 +538,14 @@ public class WicketFilter implements Filter
 
                if (applicationFactory != null)
                {
-                       applicationFactory.destroy(this);
+                       try
+                       {
+                               applicationFactory.destroy(this);
+                       }
+                       finally
+                       {
+                               applicationFactory = null;
+                       }
                }
        }
 

Reply via email to