Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48760
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 9 Mar 2010 13:15:15 +0000 (13:15 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 9 Mar 2010 13:15:15 +0000 (13:15 +0000)
Remove potential race condition that can result in multiple threads trying to use the same InputStream

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@920858 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/naming/resources/FileDirContext.java
java/org/apache/naming/resources/WARDirContext.java

index 9b556fe..6ef0d4e 100644 (file)
@@ -892,7 +892,7 @@ public class FileDirContext extends BaseDirContext {
 
 
     /**
-     * This specialized resource implementation avoids opening the IputStream
+     * This specialized resource implementation avoids opening the InputStream
      * to the file right away (which would put a lock on the file).
      */
     protected class FileResource extends Resource {
@@ -933,7 +933,9 @@ public class FileDirContext extends BaseDirContext {
         public InputStream streamContent()
             throws IOException {
             if (binaryContent == null) {
-                inputStream = new FileInputStream(file);
+                FileInputStream fis = new FileInputStream(file);
+                inputStream = fis;
+                return fis;
             }
             return super.streamContent();
         }
index 1c975b7..4702b95 100644 (file)
@@ -979,7 +979,9 @@ public class WARDirContext extends BaseDirContext {
             throws IOException {
             try {
                 if (binaryContent == null) {
-                    inputStream = base.getInputStream(entry);
+                    InputStream is = base.getInputStream(entry);
+                    inputStream = is;
+                    return is;
                 }
             } catch (ZipException e) {
                 throw new IOException(e.getMessage());