]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7485 don't let exceptions go up to Tomcat
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 20 Feb 2017 17:39:28 +0000 (18:39 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 24 Feb 2017 19:27:07 +0000 (20:27 +0100)
instead, they are logged in PlatformServletContextListener but a dedicated exception is thrown to make Tomcat's startup fail

server/sonar-server/src/main/java/org/sonar/server/platform/web/AbortTomcatStartException.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/web/PlatformServletContextListener.java

diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/AbortTomcatStartException.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/AbortTomcatStartException.java
new file mode 100644 (file)
index 0000000..a625960
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.web;
+
+/**
+ * An exception without any stacktrace nor message which point is solely to make tomcat startup fail during
+ * initialization of the Context Listener {@link PlatformServletContextListener}.
+ */
+public class AbortTomcatStartException extends RuntimeException {
+  public AbortTomcatStartException() {
+    super("Aborting tomcat servlet context startup");
+  }
+
+  /**
+   * Does not fill in the stack trace
+   *
+   * @see Throwable#fillInStackTrace()
+   */
+  @Override
+  public synchronized Throwable fillInStackTrace() {
+    return this;
+  }
+
+  @Override
+  public String toString() {
+    return getMessage();
+  }
+}
index 36dc9ccdde937c5dffdcaca61923947a6719047d..4a9bdd2c122a9fb7edd8a2b4b9e7124385763c91 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.server.platform.web;
 
-import com.google.common.base.Throwables;
 import java.util.Enumeration;
 import java.util.Properties;
 import javax.servlet.ServletContext;
@@ -48,8 +47,9 @@ public final class PlatformServletContextListener implements ServletContextListe
       Loggers.get(Platform.class).error("Web server startup failed: " + e.getMessage());
       stopQuietly();
     } catch (Throwable t) {
+      Loggers.get(Platform.class).error("Web server startup failed", t);
       stopQuietly();
-      throw Throwables.propagate(t);
+      throw new AbortTomcatStartException();
     }
   }