← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10736: Fixed potential resource leak in about page

 

------------------------------------------------------------
revno: 10736
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-05-02 13:23:34 +0200
message:
  Fixed potential resource leak in about page
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/about/action/AboutAction.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/about/action/AboutAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/about/action/AboutAction.java	2012-11-07 08:12:06 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/about/action/AboutAction.java	2013-05-02 11:23:34 +0000
@@ -36,6 +36,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.external.location.LocationManagerException;
@@ -45,6 +46,7 @@
 import org.hisp.dhis.system.util.SystemUtils;
 import org.hisp.dhis.user.CurrentUserService;
 import org.hisp.dhis.util.ContextUtils;
+import org.springframework.core.io.ClassPathResource;
 
 import com.opensymphony.xwork2.Action;
 
@@ -192,25 +194,32 @@
         // Version
         // ---------------------------------------------------------------------
 
-        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-
-        InputStream in = classLoader.getResourceAsStream( "build.properties" );
-
-        if ( in != null )
+        ClassPathResource resource = new ClassPathResource( "build.properties" );
+        
+        if ( resource.isReadable() )
         {
-            Properties properties = new Properties();
-    
-            properties.load( in );
-    
-            version = properties.getProperty( "build.version" );
-    
-            revision = properties.getProperty( "build.revision" );
-    
-            String buildTime = properties.getProperty( "build.time" );
-
-            DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
-
-            this.buildTime = dateFormat.parse( buildTime );
+            InputStream in = resource.getInputStream();
+            
+            try
+            {
+                Properties properties = new Properties();
+        
+                properties.load( in );
+        
+                version = properties.getProperty( "build.version" );
+        
+                revision = properties.getProperty( "build.revision" );
+        
+                String buildTime = properties.getProperty( "build.time" );
+    
+                DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
+    
+                this.buildTime = dateFormat.parse( buildTime );
+            }
+            finally
+            {
+                IOUtils.closeQuietly( in );
+            }
         }
         
         HttpServletRequest request = ServletActionContext.getRequest();