peony2012 / urlrewritefilter

Automatically exported from code.google.com/p/urlrewritefilter
Other
0 stars 0 forks source link

Memory leak in UrlRewriteFilter#getFullVersionString #113

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The input stream opened for the properties file is never closed. A long running 
container will drain memory. Close the input stream in a finally block.

Original issue reported on code.google.com by 1983-01...@gmx.net on 21 Jul 2012 at 5:49

GoogleCodeExporter commented 9 years ago
Done
http://code.google.com/p/urlrewritefilter/source/detail?r=423

Original comment by p...@tuckey.org on 24 Jul 2012 at 8:28

GoogleCodeExporter commented 9 years ago
You can avoid the duplicate try-catch clause by doing:

    public static String getFullVersionString() {
        Properties props = new Properties();
        String buildNumberStr = "";
        InputStream is = null;
        try {
            is = UrlRewriteFilter.class.getResourceAsStream("build.number.properties");
            if ( is != null ) {
                props.load(is);
                String buildNumber = (String) props.get("build.number");
                if (!StringUtils.isBlank(buildNumber)){
                    buildNumberStr =  props.get("project.version") + " build " + props.get("build.number");
                }
            }   
        } catch (IOException e) {
            log.error(e);
        } finally {
            if ( is != null)
                is.close();
        }

        return buildNumberStr;
    }

Original comment by 1983-01...@gmx.net on 24 Jul 2012 at 10:21