Author: julien_viet
Date: 2010-10-22 17:39:58 -0400 (Fri, 22 Oct 2010)
New Revision: 4791
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
Log:
- stream potentially not closed when an exception occurs
- use Safe.close(Closeable) when possible
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java 2010-10-22
21:21:07 UTC (rev 4790)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/portal/resource/GateInSkinConfigDeployer.java 2010-10-22
21:39:58 UTC (rev 4791)
@@ -19,6 +19,7 @@
package org.exoplatform.portal.resource;
+import org.exoplatform.commons.utils.Safe;
import org.exoplatform.commons.xml.DocumentSource;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
@@ -73,36 +74,34 @@
if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
{
ServletContext scontext = null;
+ InputStream is = null;
try
{
scontext = event.getWebApp().getServletContext();
- InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- if (is == null)
- return;
- try
+ is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
+ if (is != null)
{
- is.close();
- }
- catch (Exception ex)
- {
- // ignore me
- }
- final PortalContainerPostInitTask task = new
PortalContainerPostInitTask()
- {
-
- public void execute(ServletContext scontext, PortalContainer
portalContainer)
+ final PortalContainerPostInitTask task = new
PortalContainerPostInitTask()
{
- register(scontext, portalContainer);
- skinService.registerContext(scontext);
- }
- };
- PortalContainer.addInitTask(scontext, task, portalContainerName);
+
+ public void execute(ServletContext scontext, PortalContainer
portalContainer)
+ {
+ register(scontext, portalContainer);
+ skinService.registerContext(scontext);
+ }
+ };
+ PortalContainer.addInitTask(scontext, task, portalContainerName);
+ }
}
catch (Exception ex)
{
log.error("An error occurs while registering '" +
GATEIN_CONFIG_RESOURCE + "' from the context '"
+ (scontext == null ? "unknown" :
scontext.getServletContextName()) + "'", ex);
}
+ finally
+ {
+ Safe.close(is);
+ }
}
}
}
Modified:
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java
===================================================================
---
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2010-10-22
21:21:07 UTC (rev 4790)
+++
portal/trunk/component/web/resources/src/main/java/org/exoplatform/web/application/javascript/JavascriptDeployer.java 2010-10-22
21:39:58 UTC (rev 4791)
@@ -19,6 +19,7 @@
package org.exoplatform.web.application.javascript;
+import org.exoplatform.commons.utils.Safe;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
import org.exoplatform.services.log.ExoLogger;
@@ -29,7 +30,6 @@
import org.gatein.wci.impl.DefaultServletContainerFactory;
import org.picocontainer.Startable;
-import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletContext;
@@ -80,37 +80,34 @@
WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
{
+ InputStream is = null;
ServletContext scontext = null;
try
{
scontext = event.getWebApp().getServletContext();
-
- InputStream is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
- if (is == null)
- return;
- try
+ is = scontext.getResourceAsStream(GATEIN_CONFIG_RESOURCE);
+ if (is != null)
{
- is.close();
- }
- catch (Exception ex)
- {
- // ignore me
- }
- final PortalContainerPostInitTask task = new
PortalContainerPostInitTask()
- {
-
- public void execute(ServletContext scontext, PortalContainer
portalContainer)
+ final PortalContainerPostInitTask task = new
PortalContainerPostInitTask()
{
- register(scontext, portalContainer);
- }
- };
- PortalContainer.addInitTask(scontext, task, portalContainerName);
+
+ public void execute(ServletContext scontext, PortalContainer
portalContainer)
+ {
+ register(scontext, portalContainer);
+ }
+ };
+ PortalContainer.addInitTask(scontext, task, portalContainerName);
+ }
}
catch (Exception ex)
{
LOG.error("An error occurs while registering 'Javascript in
gatein-resources.xml' from the context '"
+ (scontext == null ? "unknown" :
scontext.getServletContextName()) + "'", ex);
}
+ finally
+ {
+ Safe.close(is);
+ }
}
}
}
@@ -130,17 +127,7 @@
}
finally
{
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- // ignore me
- }
- }
+ Safe.close(is);
}
}
}
\ No newline at end of file
Show replies by date