]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed potential problem with file descriptors remaining in use
authorArtur Signell <artur@vaadin.com>
Thu, 5 Apr 2012 14:10:22 +0000 (17:10 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 5 Apr 2012 14:10:22 +0000 (17:10 +0300)
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java

index 90efdf229628a650defcfb23ea0feaa24fda1b56..9f1691112be3bf38a8414fe9e6dfc3285ebc6737 100644 (file)
@@ -15,6 +15,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.security.GeneralSecurityException;
 import java.util.Arrays;
 import java.util.Collection;
@@ -34,6 +35,8 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import sun.net.www.protocol.file.FileURLConnection;
+
 import com.vaadin.Application;
 import com.vaadin.Application.ApplicationStartEvent;
 import com.vaadin.Application.SystemMessages;
@@ -1123,8 +1126,10 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
 
         // Find the modification timestamp
         long lastModifiedTime = 0;
+        URLConnection connection = null;
         try {
-            lastModifiedTime = resourceUrl.openConnection().getLastModified();
+            connection = resourceUrl.openConnection();
+            lastModifiedTime = connection.getLastModified();
             // Remove milliseconds to avoid comparison problems (milliseconds
             // are not returned by the browser in the "If-Modified-Since"
             // header).
@@ -1140,6 +1145,21 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                     Level.FINEST,
                     "Failed to find out last modified timestamp. Continuing without it.",
                     e);
+        } finally {
+            if (connection instanceof FileURLConnection) {
+                try {
+                    // Explicitly close the input stream to prevent it
+                    // from remaining hanging
+                    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700
+                    InputStream is = connection.getInputStream();
+                    if (is != null) {
+                        is.close();
+                    }
+                } catch (IOException e) {
+                    logger.log(Level.INFO,
+                            "Error closing FileURLConnection input stream", e);
+                }
+            }
         }
 
         // Set type mime type if we can determine it based on the filename