Bug 55995 - java.lang.NullPointerException at org.apache.jasper.servlet.JspCServletContext.getResource(JspCServletContext.java:344)
Summary: java.lang.NullPointerException at org.apache.jasper.servlet.JspCServletContex...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 8.0.0-RC10
Hardware: Other Linux
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-13 05:55 UTC by Peter Lenahan
Modified: 2014-01-14 14:49 UTC (History)
0 users



Attachments
jspc_55995_test.bat (925 bytes, text/plain)
2014-01-13 22:39 UTC, Konstantin Kolinko
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Lenahan 2014-01-13 05:55:30 UTC
Null pointer exception when running JSPC from a Shell Script.

JspCServletContext.java:344
    /**
     * Return a URL object of a resource that is mapped to the
     * specified context-relative path.
     *
     * @param path Context-relative path of the desired resource
     *
     * @exception MalformedURLException if the resource path is
     *  not properly formed
     */
    @Override
    public URL getResource(String path) throws MalformedURLException {

        if (!path.startsWith("/"))
            throw new MalformedURLException("Path '" + path +
                                            "' does not start with '/'");

TldCache.java:124

    private long[] getLastModified(TldResourcePath tldResourcePath) {
        long[] result = new long[2];
        result[0] = -1;
        result[1] = -1;
        try {
            URL url = servletContext.getResource(tldResourcePath.getWebappPath());


/usr/java/jdk1.7.0_45/bin/java -classpath :/home/tomcat/apache-tomcat-8.0.0-RC10/lib/catalina-storeconfig.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-websocket.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-i18n-es.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/catalina-tribes.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/catalina-ha.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-i18n-ja.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/jsp-api.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-util.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-jni.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/jasper.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/websocket-api.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/ecj-4.3.1.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-i18n-fr.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-api.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-coyote.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/servlet-api.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/jasper-el.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/catalina.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-dbcp.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-jdbc.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/annotations-api.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-util-scan.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/catalina-ant.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/el-api.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/lib/tomcat-spdy.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/bin/tomcat-juli.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/bin/bootstrap.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/bin/commons-daemon.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/webapps/examples/WEB-INF/lib/jstl.jar:/home/tomcat/apache-tomcat-8.0.0-RC10/webapps/examples/WEB-INF/lib/standard.jar:/home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/lib/ant-1.6.5.jar org.apache.jasper.JspC 	-d /home/java/source/HEAD/work/tomcat80 	-v 	-l 	-uriroot /home/java/source/HEAD/work/jsp_compile_shared /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/dialog/qbAxesDlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/dialog/qbManualGecodingDlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/fmtdlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/index.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/joindlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/producer.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/simplefilter.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/selectvaluedlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/binddowsTestView.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/variableeditordlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/filterprompteditor.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/ajax_response.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/fontdlg.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/join_fields.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/tree_component.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/waiting_banner.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/folderblock/BID_FolderBlockInit.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/folderblock/BID_FolderBlockBoot.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/BID_EmptyContent.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/xml/BID_UrlProperties.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/xml/BID_IBFSpathToHrefs.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/xml/BID_xmlresponse.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/xml/BID_statusResponse.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/favorites/BID_favorites_tree.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/favorites/BID_FavoritesBlockBoot.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/favorites/BID_FavoritesBlockInit.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/favorites/BID_favorites_tree_boot.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/favorites/BID_listToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/index.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_InternalPage.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_SearchTree_Boot.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_SATree_Boot.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_BiFrame.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_initView.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_ShowToolbar.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_ExternalPage.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_SATreeBiFrame.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_initBindows.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/views/BID_SearchTreeBiFrame.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/recents/BID_recents_tree_boot.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/recents/BID_recents_tree.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/recents/BID_listToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/error.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/groups/BID_listToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/search/BID_searchListToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/search/BID_listToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/tree/BID_MrPropertiesToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/tree/BID_flatListToXML.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/tree/BID_PlainText.jsp /home/java/source/HEAD/work/jsp_compile_shared/WEB-INF/jsp/bid/tree/BID_listToXML.jsp	  2>&1
	
	
Exception in thread "main" java.lang.NullPointerException
	at org.apache.jasper.servlet.JspCServletContext.getResource(JspCServletContext.java:344)
	at org.apache.jasper.compiler.TldCache.getLastModified(TldCache.java:124)
	at org.apache.jasper.compiler.TldCache.<init>(TldCache.java:70)
	at org.apache.jasper.JspC.initServletContext(JspC.java:1468)
	at org.apache.jasper.JspC.execute(JspC.java:1321)
	at org.apache.jasper.JspC.main(JspC.java:269)
Comment 1 Mark Thomas 2014-01-13 17:48:43 UTC
I can't reproduce this with the latest 8.0.x source. Neither do I see anything in the change history since RC10 that looks like it would have fixed this.

Without the JSP source it is hard to see what might be triggering this. Please provide the simplest possible JSP that demonstrates this issue along with any additional files (tags etc) that may be required to reproduce it.
Comment 2 Mark Thomas 2014-01-13 17:50:28 UTC
Drop severity to a realistic level. It isn't functionality used by most users and in at least some cases JspC still works.
Comment 3 Konstantin Kolinko 2014-01-13 22:39:03 UTC
Created attachment 31203 [details]
jspc_55995_test.bat

I can reproduce this NPE with 8.0-RC10 and with trunk.

See the attached Windows batch file. Essentially, it uses Tomcat's bin/cpappend.bat to reproduce classpath from Comment 0. That is

1. ant.jar
2. all jars from %CATALINA_HOME%\bin and %CATALINA_HOME%\lib
3. libs from the examples webapp (the JSTL jars)

Then it tries to compile examples\jsp\tagplugin\choose.jsp.
This results in the same NullPointerException, as reported by OP.

Exception in thread "main" java.lang.NullPointerException
        at org.apache.jasper.servlet.JspCServletContext.getResource(JspCServletContext.java:344)
        at org.apache.jasper.compiler.TldCache.getLastModified(TldCache.java:124)
        at org.apache.jasper.compiler.TldCache.<init>(TldCache.java:70)
        at org.apache.jasper.JspC.initServletContext(JspC.java:1468)
        at org.apache.jasper.JspC.execute(JspC.java:1321)
        at org.apache.jasper.JspC.main(JspC.java:269)

4. If I comment-out the line that adds JSTL jars to the classpath,
JspC completes successfully and generates Java source text for the page.
Note, that the JSTL tag library in the WEB-INF/lib directory of the web application is successfully recognized and processed by JspC.
Comment 4 Mark Thomas 2014-01-14 12:05:30 UTC
Thanks for the test case. The bit I was missing as explicitly putting the JARs containing TLDs on the class path.

This has been fixed in 8.0.x and will be included in 8.0.0 onwards.
Comment 5 Peter Lenahan 2014-01-14 14:49:02 UTC
Konstantin, Mark,

Thank you both for reproducing the problem in a better way and fixing it so fast.

Peter