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 748 forks source link

Method not found: class java.nio.file.Paths.get(java.lang.String) in configuration with sub-repositories #2806

Closed liucongvg closed 5 years ago

liucongvg commented 5 years ago

My exception is:

javax.servlet.jsp.JspException: org.apache.jasper.el.JspELException: /WEB-INF/tags/repository.tag(44,4) '${Paths.get(pageConfig.sourceRootPath).relativize(Paths.get(repositoryInfo.directoryName))}' Method not found: class java.nio.file.Paths.get(java.lang.String)
    at org.apache.jsp.tag.web.repository_tag.doTag(repository_tag.java:270)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_opengrok_005frepository_005f0(repositories_tag.java:364)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fif_005f2(repositories_tag.java:331)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fforEach_005f1(repositories_tag.java:294)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fif_005f1(repositories_tag.java:257)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fforEach_005f0(repositories_tag.java:220)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fif_005f0(repositories_tag.java:185)
    at org.apache.jsp.tag.web.repositories_tag.doTag(repositories_tag.java:144)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:843)
    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)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:401)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:345)
    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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.opengrok.web.StatisticsFilter.doFilter(StatisticsFilter.java:59)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.opengrok.web.AuthorizationFilter.doFilter(AuthorizationFilter.java:98)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    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: org.apache.jasper.el.JspELException: /WEB-INF/tags/repository.tag(44,4) '${Paths.get(pageConfig.sourceRootPath).relativize(Paths.get(repositoryInfo.directoryName))}' Method not found: class java.nio.file.Paths.get(java.lang.String)
    at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:123)
    at org.apache.jsp.tag.web.repository_tag._jspx_meth_c_005fset_005f6(repository_tag.java:431)
    at org.apache.jsp.tag.web.repository_tag._jspx_meth_c_005fif_005f0(repository_tag.java:405)
    at org.apache.jsp.tag.web.repository_tag.doTag(repository_tag.java:209)
    ... 41 more

I run the following command to show my tomcat process ps -aux | grep tomcat the output is:

tomcat8    2270 13.8  2.0 4778312 333112 ?      Sl   20:25   3:12 /home/liucong/Downloads/jdk1.8.0_211/bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC -Djava.endorsed.dirs=/usr/share/tomcat8/endorsed -classpath /usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat8 -Dcatalina.home=/usr/share/tomcat8 -Djava.io.tmpdir=/tmp/tomcat8-tomcat8-tmp org.apache.catalina.startup.Bootstrap start

And my os information is: Linux ubuntu 4.15.0-51-generic #55~16.04.1-Ubuntu SMP Thu May 16 09:24:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

And my opengrok version is: 1.2.9

vladak commented 5 years ago

Huh, I thought java.nio.file.Paths is part of core Java so it should be always present. And it seems you're running Java 8 so any modularization issues are not relevant.

When exactly does this happen ?

vladak commented 5 years ago

Possibly related to #2719. repository.tag contains:

<%@ tag import="java.nio.file.Paths" %>
liucongvg commented 5 years ago

Huh, I thought java.nio.file.Paths is part of core Java so it should be always present. And it seems you're running Java 8 so any modularization issues are not relevant.

When exactly does this happen ?

sudo cp source.war /var/lib/tomcat8/webapps/other_name.war

Maybe this have something to do with the war rename. and maybe I should try the rename with opengrok tools, but I encountered another problem #2810

vladak commented 5 years ago

I don't think the way the web app is deployed matters in this case. opengrok-deploy just performs a copy of the file, modulo modification of configuration path within.

vladak commented 5 years ago

Is the exception is thrown on every page or just some ?

vladak commented 5 years ago

The problem might be in the parameters. The exception is 'method not found' rather than 'class not found'. Java 8 defines 2 get() methods in https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html:

The first method signature is valid however - the elipsis can be omitted. That said, maybe you can try the suggestion from https://stackoverflow.com/questions/32202068/jmeter-static-method-get-java-lang-string-not-found-in-classjava-nio-file and manually edit repositories.tag to call the Paths.get() with varagrs parameter on the affected line (note there are 2 calls there actually): https://github.com/oracle/opengrok/blob/86491e77f078708356b66a05cd1f7cfdd4e7dde9/opengrok-web/src/main/webapp/WEB-INF/tags/repository.tag#L45

liucongvg commented 5 years ago

The problem might be in the parameters. The exception is 'method not found' rather than 'class not found'. Java 8 defines 2 get() methods in https://docs.oracle.com/javase/8/docs/api/java/nio/file/Paths.html:

  • get(String first, String... more)
  • get(URI uri)

The first method signature is valid however - the elipsis can be omitted. That said, maybe you can try the suggestion from https://stackoverflow.com/questions/32202068/jmeter-static-method-get-java-lang-string-not-found-in-classjava-nio-file and manually edit repositories.tag to call the Paths.get() with varagrs parameter on the affected line (note there are 2 calls there actually): https://github.com/oracle/opengrok/blob/86491e77f078708356b66a05cd1f7cfdd4e7dde9/opengrok-web/src/main/webapp/WEB-INF/tags/repository.tag#L45

I tried before commit this issue, but failed, my solution is:

       value="${Paths.get(URI.create(pageConfig.sourceRootPath)).relativize(Paths.get(URI.create(repositoryInfo.directoryName)))}"/>

but the new exception is:

There was an error!
org.apache.jasper.el.JspELException: /WEB-INF/tags/repository.tag(44,4) '${Paths.get(URI.create(pageConfig.sourceRootPath)).relativize(Paths.get(URI.create(repositoryInfo.directoryName)))}' java.lang.NullPointerException

javax.servlet.jsp.JspException: org.apache.jasper.el.JspELException: /WEB-INF/tags/repository.tag(44,4) '${Paths.get(URI.create(pageConfig.sourceRootPath)).relativize(Paths.get(URI.create(repositoryInfo.directoryName)))}' java.lang.NullPointerException
    at org.apache.jsp.tag.web.repository_tag.doTag(repository_tag.java:270)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_opengrok_005frepository_005f0(repositories_tag.java:364)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fif_005f2(repositories_tag.java:331)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fforEach_005f1(repositories_tag.java:294)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fif_005f1(repositories_tag.java:257)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fforEach_005f0(repositories_tag.java:220)
    at org.apache.jsp.tag.web.repositories_tag._jspx_meth_c_005fif_005f0(repositories_tag.java:185)
    at org.apache.jsp.tag.web.repositories_tag.doTag(repositories_tag.java:144)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:843)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
......
liucongvg commented 5 years ago

@vladak This may have something to do with the project size which will be indexed. If I just index one of the subdirectory of my project, there is no exception. But if I index the whole project, the exception occurs, do you have any idea about this?

vladak commented 5 years ago

Seems unlikely to me. Either the method works or does not. Also, how do you index just a subdirectory ?

vladak commented 5 years ago

Can you try replacing the Paths.get() calls with the second signature, i.e.:

value="${Paths.get(pageConfig.sourceRootPath, new String[0]).relativize(Paths.get(repositoryInfo.directoryName, new String[0]))}"/>
Conan-Kudo commented 5 years ago

@vladak I'm encountering the same problem (using v1.2.13) and I did your substitution and now I have this error:

/WEB-INF/tags/repository.tag (line: 44, column: 4) "${Paths.get(pageConfig.sourceRootPath, new String[0]).relativize(Paths.get(repositoryInfo.directoryName, new String[0]))}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${Paths.get(pageConfig.sourceRootPath, new String[0]).relativize(Paths.get(repositoryInfo.directoryName, new String[0]))}]

org.apache.jasper.JasperException: /WEB-INF/tags/repository.tag (line: 44, column: 4) "${Paths.get(pageConfig.sourceRootPath, new String[0]).relativize(Paths.get(repositoryInfo.directoryName, new String[0]))}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${Paths.get(pageConfig.sourceRootPath, new String[0]).relativize(Paths.get(repositoryInfo.directoryName, new String[0]))}]
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:275)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:91)
    at org.apache.jasper.compiler.Validator$ValidateVisitor.getJspAttribute(Validator.java:1422)
    at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1231)
    at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:879)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:898)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    at org.apache.jasper.compiler.Node$Root.accept(Node.java:464)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1853)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
    at org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:246)
    at org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:587)
    at org.apache.jasper.compiler.TagFileProcessor.access$000(TagFileProcessor.java:50)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:674)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:678)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:678)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:678)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:678)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:678)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    at org.apache.jasper.compiler.Node$Root.accept(Node.java:464)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.TagFileProcessor.loadTagFiles(TagFileProcessor.java:692)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:229)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
    at org.apache.jasper.servlet.JspServletWrapper.loadTagFile(JspServletWrapper.java:246)
    at org.apache.jasper.compiler.TagFileProcessor.loadTagFile(TagFileProcessor.java:587)
    at org.apache.jasper.compiler.TagFileProcessor.access$000(TagFileProcessor.java:50)
    at org.apache.jasper.compiler.TagFileProcessor$TagFileLoaderVisitor.visit(TagFileProcessor.java:674)
    at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1536)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    at org.apache.jasper.compiler.Node$Root.accept(Node.java:464)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2452)
    at org.apache.jasper.compiler.Node$IncludeDirective.accept(Node.java:635)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
    at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
    at org.apache.jasper.compiler.Node$Root.accept(Node.java:464)
    at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
    at org.apache.jasper.compiler.TagFileProcessor.loadTagFiles(TagFileProcessor.java:692)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:229)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:401)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:345)
    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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.opengrok.web.StatisticsFilter.doFilter(StatisticsFilter.java:59)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.opengrok.web.AuthorizationFilter.doFilter(AuthorizationFilter.java:98)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    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)
vladak commented 5 years ago

Oh, the new String[0] probably cannot be used in JSTL. Maybe we should just move the whole line to a static method in one of the already included classes.

tulinkry commented 5 years ago

Good job! You can make a static method of pageconfig - this class is always imported in the tags.

vladak commented 5 years ago

There seems to be some Tomcat configuration that makes such problems to be hidden, at least in my case - instead of reporting an exception, the resulting value is blank. I tried on a simple JSTL test code. Even totally non-existent methods within c:set value are converted to blank. Once I moved the same code to a class, it worked just fine, so there is something about Paths (or other Java core classes/methods) that makes them not directly usable in JSTL.