Bug 54472 - JspcServletContext need to set ClassLoader
Summary: JspcServletContext need to set ClassLoader
Status: RESOLVED DUPLICATE of bug 54440
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 7.0.35
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-23 06:33 UTC by moon
Modified: 2013-01-23 09:07 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***