Author: markt
Date: Tue May 29 13:06:24 2012
New Revision: 1343708

URL: http://svn.apache.org/viewvc?rev=1343708&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53081
Do not always cache resources loaded by the web application class loader

Modified:
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1343708&r1=1343707&r2=1343708&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Tue May 
29 13:06:24 2012
@@ -2945,6 +2945,7 @@ public class WebappClassLoader
 
         int contentLength = -1;
         InputStream binaryStream = null;
+        boolean isClassResource = path.endsWith(".class");
 
         int jarFilesLength = jarFiles.length;
         int repositoriesLength = repositories.length;
@@ -3146,7 +3147,20 @@ public class WebappClassLoader
                     return null;
                 }
 
-                if (binaryStream != null) {
+                /* Only cache the binary content if there is some content
+                 * available and either:
+                 * a) It is a class file since the binary content is only 
cached
+                 *    until the class has been loaded
+                 *    or
+                 * b) The file needs conversion to address encoding issues (see
+                 *    below)
+                 *
+                 * In all other cases do not cache the content to prevent
+                 * excessive memory usage if large resources are present (see
+                 * https://issues.apache.org/bugzilla/show_bug.cgi?id=53081).
+                 */
+                if (binaryStream != null &&
+                        (isClassResource || fileNeedConvert)) {
 
                     byte[] binaryContent = new byte[contentLength];
 
@@ -3248,8 +3262,15 @@ public class WebappClassLoader
         if (entry != null) {
             if (entry.binaryContent != null)
                 return new ByteArrayInputStream(entry.binaryContent);
+            else {
+                try {
+                    return entry.source.openStream();
+                } catch (IOException ioe) {
+                    // Ignore
+                }
+            }
         }
-        return (null);
+        return null;
 
     }
 



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

Reply via email to