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.36k stars 747 forks source link

null ptr exception in getSimplifiedPath() #1397

Closed vladak closed 7 years ago

vladak commented 7 years ago

when displaying xref/userland-default-prepped/components/vim/ exception was raised:

java.lang.NullPointerException
    at org.opensolaris.opengrok.web.DirectoryListing.getSimplifiedPath(DirectoryListing.java:98)
    at org.opensolaris.opengrok.web.DirectoryListing.listTo(DirectoryListing.java:188)
    at org.apache.jsp.list_jsp._jspService(list_jsp.java:608)
    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:443)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.opensolaris.opengrok.web.StatisticsFilter.doFilter(StatisticsFilter.java:55)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.opensolaris.opengrok.web.AuthorizationFilter.doFilter(AuthorizationFilter.java:66)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    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:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
vladak commented 7 years ago

The code in question does this:

96      private static String getSimplifiedPath(File dir) {
97          String[] files = dir.list();
98          if (files.length == 1) {
99              File entry = new File(dir, files[0]);
100              if (entry.isDirectory()) {
101                  return (dir.getName() + "/" + getSimplifiedPath(entry));
102              }
103          }
104          return dir.getName();
105      }

According to JavaDoc, dir.list() can return null (https://docs.oracle.com/javase/8/docs/api/java/io/File.html#list--) so check will fix this however proper root cause is needed.

vladak commented 7 years ago

I see these entries in the directory:

drwxr-xr-x   8 vkotal   staff         14 Jan 30 21:36 .
drwxr-xr-x 310 vkotal   staff        311 Jan 10 04:08 ..
-rw-r--r--   1 vkotal   staff       4880 Nov 23 00:08 Makefile
-rw-r--r--   1 vkotal   staff       2379 Oct  5 04:07 gvim.p5m
-rw-r--r--   1 vkotal   staff        753 Apr  8  2013 help_minimized.txt
drwxr-xr-x   2 vkotal   staff          8 Nov 23 00:08 patches
drwx------   2 vkotal   staff          2 Jan 30 21:36 tmpSdWCDH
drwx------   2 vkotal   staff          2 Jan 28 01:44 tmpW_VTsQ
drwx------   2 vkotal   staff          2 Jan 19 09:37 tmpY_2HPw
drwx------   2 vkotal   staff          2 Jan 25 21:37 tmprPjlq_
drwx------   2 vkotal   staff          2 Jan 27 05:34 tmptt_olX
-rw-r--r--   1 vkotal   staff       5156 Oct  5 04:07 vim-core.p5m
-rw-r--r--   1 vkotal   staff      92628 Nov 23 00:08 vim.p5m
-rw-r--r--   1 vkotal   staff        322 Oct  5 04:07 xxd.license

given the webapp runs under webservd user, it makes me wonder whether this problem is caused by the permissions on the tmp directories.

vladak commented 7 years ago

Verified - caused by permissions.