Author: kkolinko
Date: Sat Nov 22 12:27:57 2014
New Revision: 1641052

URL: http://svn.apache.org/r1641052
Log:
Fix missing Jar.close() in TagFileProcessor.loadTagFile()

With this all JarFactory.newInstance() calls are now followed by proper 
Jar.close() calls.

Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java

Modified: tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java?rev=1641052&r1=1641051&r2=1641052&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java 
(original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/TagFileProcessor.java Sat Nov 
22 12:27:57 2014
@@ -517,90 +517,96 @@ class TagFileProcessor {
             TagInfo tagInfo, PageInfo parentPageInfo) throws JasperException {
 
         Jar tagJar = null;
-        if (tagFilePath.startsWith("/META-INF/")) {
-            try {
-                tagJar = compiler.getCompilationContext().getTldResourcePath(
-                            tagInfo.getTagLibrary().getURI()).openJar();
-            } catch (IOException ioe) {
-                throw new JasperException(ioe);
+        try {
+            if (tagFilePath.startsWith("/META-INF/")) {
+                try {
+                    tagJar = 
compiler.getCompilationContext().getTldResourcePath(
+                                tagInfo.getTagLibrary().getURI()).openJar();
+                } catch (IOException ioe) {
+                    throw new JasperException(ioe);
+                }
+            }
+            String wrapperUri;
+            if (tagJar == null) {
+                wrapperUri = tagFilePath;
+            } else {
+                wrapperUri = tagJar.getURL(tagFilePath);
             }
-        }
-        String wrapperUri;
-        if (tagJar == null) {
-            wrapperUri = tagFilePath;
-        } else {
-            wrapperUri = tagJar.getURL(tagFilePath);
-        }
 
-        JspCompilationContext ctxt = compiler.getCompilationContext();
-        JspRuntimeContext rctxt = ctxt.getRuntimeContext();
+            JspCompilationContext ctxt = compiler.getCompilationContext();
+            JspRuntimeContext rctxt = ctxt.getRuntimeContext();
+
+            synchronized (rctxt) {
+                JspServletWrapper wrapper = rctxt.getWrapper(wrapperUri);
+                if (wrapper == null) {
+                    wrapper = new JspServletWrapper(ctxt.getServletContext(), 
ctxt
+                            .getOptions(), tagFilePath, tagInfo, ctxt
+                            .getRuntimeContext(), tagJar);
+                    rctxt.addWrapper(wrapperUri, wrapper);
 
-        synchronized (rctxt) {
-            JspServletWrapper wrapper = rctxt.getWrapper(wrapperUri);
-            if (wrapper == null) {
-                wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt
-                        .getOptions(), tagFilePath, tagInfo, ctxt
-                        .getRuntimeContext(), tagJar);
-                rctxt.addWrapper(wrapperUri, wrapper);
-
-                // Use same classloader and classpath for compiling tag files
-                wrapper.getJspEngineContext().setClassLoader(
-                        ctxt.getClassLoader());
-                
wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
-            } else {
-                // Make sure that JspCompilationContext gets the latest TagInfo
-                // for the tag file. TagInfo instance was created the last
-                // time the tag file was scanned for directives, and the tag
-                // file may have been modified since then.
-                wrapper.getJspEngineContext().setTagInfo(tagInfo);
-            }
-
-            Class<?> tagClazz;
-            int tripCount = wrapper.incTripCount();
-            try {
-                if (tripCount > 0) {
-                    // When tripCount is greater than zero, a circular
-                    // dependency exists. The circularly dependent tag
-                    // file is compiled in prototype mode, to avoid infinite
-                    // recursion.
-
-                    JspServletWrapper tempWrapper = new JspServletWrapper(ctxt
-                            .getServletContext(), ctxt.getOptions(),
-                            tagFilePath, tagInfo, ctxt.getRuntimeContext(),
-                            tagJar);
                     // Use same classloader and classpath for compiling tag 
files
-                    tempWrapper.getJspEngineContext().setClassLoader(
+                    wrapper.getJspEngineContext().setClassLoader(
                             ctxt.getClassLoader());
-                    
tempWrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
-                    tagClazz = tempWrapper.loadTagFilePrototype();
-                    tempVector.add(tempWrapper.getJspEngineContext()
-                            .getCompiler());
+                    
wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
                 } else {
-                    tagClazz = wrapper.loadTagFile();
+                    // Make sure that JspCompilationContext gets the latest 
TagInfo
+                    // for the tag file. TagInfo instance was created the last
+                    // time the tag file was scanned for directives, and the 
tag
+                    // file may have been modified since then.
+                    wrapper.getJspEngineContext().setTagInfo(tagInfo);
                 }
-            } finally {
-                wrapper.decTripCount();
-            }
 
-            // Add the dependents for this tag file to its parent's
-            // Dependent list. The only reliable dependency information
-            // can only be obtained from the tag instance.
-            try {
-                Object tagIns = tagClazz.newInstance();
-                if (tagIns instanceof JspSourceDependent) {
-                    Iterator<Entry<String,Long>> iter = ((JspSourceDependent)
-                            tagIns).getDependants().entrySet().iterator();
-                    while (iter.hasNext()) {
-                        Entry<String,Long> entry = iter.next();
-                        parentPageInfo.addDependant(entry.getKey(),
-                                entry.getValue());
+                Class<?> tagClazz;
+                int tripCount = wrapper.incTripCount();
+                try {
+                    if (tripCount > 0) {
+                        // When tripCount is greater than zero, a circular
+                        // dependency exists. The circularly dependent tag
+                        // file is compiled in prototype mode, to avoid 
infinite
+                        // recursion.
+
+                        JspServletWrapper tempWrapper = new 
JspServletWrapper(ctxt
+                                .getServletContext(), ctxt.getOptions(),
+                                tagFilePath, tagInfo, ctxt.getRuntimeContext(),
+                                tagJar);
+                        // Use same classloader and classpath for compiling 
tag files
+                        tempWrapper.getJspEngineContext().setClassLoader(
+                                ctxt.getClassLoader());
+                        
tempWrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
+                        tagClazz = tempWrapper.loadTagFilePrototype();
+                        tempVector.add(tempWrapper.getJspEngineContext()
+                                .getCompiler());
+                    } else {
+                        tagClazz = wrapper.loadTagFile();
                     }
+                } finally {
+                    wrapper.decTripCount();
                 }
-            } catch (Exception e) {
-                // ignore errors
-            }
 
-            return tagClazz;
+                // Add the dependents for this tag file to its parent's
+                // Dependent list. The only reliable dependency information
+                // can only be obtained from the tag instance.
+                try {
+                    Object tagIns = tagClazz.newInstance();
+                    if (tagIns instanceof JspSourceDependent) {
+                        Iterator<Entry<String,Long>> iter = 
((JspSourceDependent)
+                                tagIns).getDependants().entrySet().iterator();
+                        while (iter.hasNext()) {
+                            Entry<String,Long> entry = iter.next();
+                            parentPageInfo.addDependant(entry.getKey(),
+                                    entry.getValue());
+                        }
+                    }
+                } catch (Exception e) {
+                    // ignore errors
+                }
+
+                return tagClazz;
+            }
+        } finally {
+            if (tagJar != null) {
+                tagJar.close();
+            }
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to