From 2f395ab251b336a1ba32b01742cfc93f075184f0 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 5 Apr 2012 17:10:22 +0300 Subject: [PATCH] Fixed potential problem with file descriptors remaining in use --- .../server/AbstractApplicationServlet.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 90efdf2296..9f1691112b 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -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 -- 2.39.5