jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From juanpa...@apache.org
Subject svn commit: r1553555 - /jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
Date Thu, 26 Dec 2013 19:18:10 GMT
Author: juanpablo
Date: Thu Dec 26 19:18:09 2013
New Revision: 1553555

URL: http://svn.apache.org/r1553555
Log:
sonar: Security - Array is stored directly

ensuring streams get closed

Modified:
    jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java

Modified: jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
URL: http://svn.apache.org/viewvc/jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java?rev=1553555&r1=1553554&r2=1553555&view=diff
==============================================================================
--- jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
(original)
+++ jspwiki/trunk/jspwiki-war/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java
Thu Dec 26 19:18:09 2013
@@ -32,6 +32,7 @@ import java.util.Iterator;
 import java.util.Properties;
 import java.util.Vector;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.lucene.analysis.Analyzer;
@@ -79,13 +80,14 @@ import org.apache.wiki.util.ClassUtil;
 import org.apache.wiki.util.FileUtil;
 import org.apache.wiki.util.TextUtil;
 
+
 /**
  *  Interface for the search providers that handle searching the Wiki
  *
  *  @since 2.2.21.
  */
-public class LuceneSearchProvider implements SearchProvider
-{
+public class LuceneSearchProvider implements SearchProvider {
+
     protected static final Logger log = Logger.getLogger(LuceneSearchProvider.class);
 
     private WikiEngine m_engine;
@@ -341,35 +343,34 @@ public class LuceneSearchProvider implem
             }
         }
 
+        String out = null;
         if( searchSuffix )
         {
-            InputStream attStream;
-
+            InputStream attStream = null;
+            StringWriter sout = new StringWriter();
+            
             try
             {
                 attStream = mgr.getAttachmentStream( att );
-
-                StringWriter sout = new StringWriter();
                 FileUtil.copyContents( new InputStreamReader(attStream), sout );
-
-                attStream.close();
-                sout.close();
-
-                return sout.toString();
+                out = sout.toString();
             }
             catch (ProviderException e)
             {
                 log.error("Attachment cannot be loaded", e);
-                return null;
             }
             catch (IOException e)
             {
                 log.error("Attachment cannot be loaded", e);
-                return null;
+            }
+            finally 
+            {
+            	IOUtils.closeQuietly( attStream );
+            	IOUtils.closeQuietly( sout );
             }
         }
 
-        return null;
+        return out;
     }
 
     /**
@@ -800,7 +801,7 @@ public class LuceneSearchProvider implem
         {
             m_page  = page;
             m_score = score;
-            m_contexts = contexts;
+            m_contexts = contexts != null ? contexts.clone() : null;
         }
 
         public WikiPage getPage()



Mime
View raw message