oracle / opengrok

OpenGrok is a fast and usable source code search and cross reference engine, written in Java
http://oracle.github.io/opengrok/
Other
4.34k stars 745 forks source link

static initializer of AnalyzerGuru causing hard to detect deployment problems #2027

Open vladak opened 6 years ago

vladak commented 6 years ago

After not using my mac mini workstation (running macOS 10.13.3) for a while to run OpenGrok, I decided to give it a try and do a mini project in Netbeans. To my dismay, the webapp could not be loaded. It deployed fine however then got an exception when rendering the index page:

26-Feb-2018 16:33:31.202 SEVERE [190] org.apache.catalina.core.StandardHostValve.custom Exception Processing ErrorPage[errorCode=500, location=/error]
 org.apache.jasper.JasperException: An exception occurred processing JSP page /menu.jspf at line 201

198:                 String selection = queryParams.getType();
199:                 %>
200:                 <option value="">Any</option><%
201:                 for (Map.Entry<String, String> d : SearchHelper.getFileTypeDescriptions()) {
202:                     %>
203:                 <option value="<%= Util.formQuoteEscape(d.getKey()) %>"<%
204:                     if (d.getKey().equals(selection)) {

Stacktrace:
    at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:579)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:716)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:468)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
    at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:442)
    at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:301)
    at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:396)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:176)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class org.opensolaris.opengrok.analysis.AnalyzerGuru
    at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
    at org.apache.jsp.error_jsp._jspService(error_jsp.java:667)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    ... 25 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.opensolaris.opengrok.analysis.AnalyzerGuru
    at org.opensolaris.opengrok.web.SearchHelper.getFileTypeDescriptions(SearchHelper.java:217)
    at org.apache.jsp.error_jsp._jspService(error_jsp.java:532)
    ... 28 more

According to https://stackoverflow.com/questions/7325579/java-lang-noclassdeffounderror-could-not-initialize-class-xxx this is caused by code in the static initializer. Indeed, AnalyzerGuru has lots of stuff that can fail in there. I added try/catch block with logging+rethrow there however could not see it anywhere (like https://stackoverflow.com/questions/19999590/tomcat-6-error-in-static-initialiser-is-hidden-by-noclassdeffounderror?noredirect=1&lq=1).

Next, I constructed trivial test case to call AnalyzerGuru.getfileTypeDescriptions() to see if the problem surfaces there however to no avail.

Next, I commented out most of the stuff in the analyzers array and the problem disappeared however after uncommenting them again I cannot reproduce it anymore so either it is transient or depends on other external factors or there has to be some JVM/Tomcat/Netbeans dance performed to refresh the war file (I dutifuly did full rebuild, restart, redeploy each time).

idodeclare commented 6 years ago

I have a PR queued up: "Refactor AnalyzerGuru, HistoryGuru as non-singleton" (370bfa3c852), that addresses this. It's eighth after the current PR #2017.

vladak commented 6 years ago

Cool, the less singletons the better.

Dne 26. 2. 2018 5:09 odp. napsal uživatel "C Fraire" < notifications@github.com>:

I have a PR queued up: "Refactor AnalyzerGuru, HistoryGuru as non-singleton" (370bfa3 https://github.com/oracle/opengrok/commit/370bfa3c8528ae736e231db81a6bcf39bd424e8b), that addresses this. It's eighth after the current PR #2017 https://github.com/oracle/opengrok/pull/2017.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/oracle/opengrok/issues/2027#issuecomment-368554139, or mute the thread https://github.com/notifications/unsubscribe-auth/ACzGDHUIcqDBanI0bi1o6bbkNXfjFdUzks5tYtc6gaJpZM4STegC .