Bug 54472

Summary: JspcServletContext need to set ClassLoader
Product: Tomcat 7 Reporter: moon <aceofmoon>
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 7.0.35   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description moon 2013-01-23 06:33:00 UTC
Now, JspcServletContext

    @Override
    public ClassLoader getClassLoader() {
        return null;
    }
i.e. no classloader is set.

This maybe throw NPE.
Actually, by rev. 1431228, 

    private void init(ErrorDispatcher err) throws JasperException {
        if (initialized)
            return;

        tagPlugins = new HashMap<String, TagPlugin>();

        Enumeration<URL> urls = null;
        try {
            urls = ctxt.getClassLoader().getResources(
                    META_INF_JASPER_TAG_PLUGINS_XML);
        } catch (IOException ioe) {
            throw new JasperException(ioe);
        }

        ....
    }

threw NPE, because ctxt.getClassLoader() is null.

So, we need to set the classloader in JspServletContext.
I resolved this issue by adding setter of classloader in JspServletContext and setting classloader in JspC like below.


    protected void processFile(String file)
        throws JasperException
    {

            ....
            originalClassLoader = Thread.currentThread().getContextClassLoader();
            if( loader==null ) {
                initClassLoader( clctxt );
                context.setClassLoader(loader); <-- set classloader
            }

   }
Comment 1 Mark Thomas 2013-01-23 09:07:47 UTC

*** This bug has been marked as a duplicate of bug 54440 ***