Author: olga
Date: Fri Oct 16 00:16:57 2009
New Revision: 825712

URL: http://svn.apache.org/viewvc?rev=825712&view=rev
Log:
PIG-1009: FINDBUGS: OS_OPEN_STREAM: Method may fail to close stream (olgan)

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/Main.java
    hadoop/pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java
    hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java
    
hadoop/pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=825712&r1=825711&r2=825712&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Fri Oct 16 00:16:57 2009
@@ -26,6 +26,8 @@
 
 IMPROVEMENTS
 
+PIG-1009: FINDBUGS: OS_OPEN_STREAM: Method may fail to close stream (olgan)
+
 PIG-1008: FINDBUGS: NP_TOSTRING_COULD_RETURN_NULL (olgan)
 
 PIG-1018: FINDBUGS: NM_FIELD_NAMING_CONVENTION: Field names should start with

Modified: hadoop/pig/trunk/src/org/apache/pig/Main.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/Main.java?rev=825712&r1=825711&r2=825712&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/Main.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/Main.java Fri Oct 16 00:16:57 2009
@@ -463,15 +463,20 @@
     }
     
     Properties props = new Properties();
+    FileReader propertyReader = null;
     if (log4jconf != null) {
         try {
-            FileReader propertyReader = new FileReader(log4jconf);
+            propertyReader = new FileReader(log4jconf);
             props.load(propertyReader);
         }
         catch (IOException e)
         {
             System.err.println("Warn: Cannot open log4j properties file, use 
default");
         }
+        finally
+        {
+            if (propertyReader != null) try {propertyReader.close();} 
catch(Exception e) {}
+        }
     }
     if (props.size() == 0) {
         props.setProperty("log4j.rootLogger", "INFO, PIGCONSOLE");

Modified: hadoop/pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java?rev=825712&r1=825711&r2=825712&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/io/FileLocalizer.java Fri Oct 16 
00:16:57 2009
@@ -664,12 +664,16 @@
         if (exitVal != 0)
             return null;
         String line = null;
+        BufferedReader br = null;
         try {
             InputStreamReader isr = new InputStreamReader(p.getInputStream());
-            BufferedReader br = new BufferedReader(isr);
+            br = new BufferedReader(isr);
             line = br.readLine();
+            isr.close();
         } catch (IOException e) {
             return null;
+        } finally {
+            if (br != null) try {br.close();} catch (Exception e) {}
         }
         return line;
     }

Modified: hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java?rev=825712&r1=825711&r2=825712&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java (original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/util/PropertiesUtil.java Fri Oct 
16 00:16:57 2009
@@ -35,9 +35,11 @@
     private final static Log log = LogFactory.getLog(PropertiesUtil.class);
 
     public static void loadPropertiesFromFile(Properties properties) {
+        InputStream inputStream = null;
+        BufferedInputStream bis = null;
         try {
             Class<PropertiesUtil> clazz = PropertiesUtil.class;
-            InputStream inputStream = clazz
+            inputStream = clazz
                     .getResourceAsStream(PROPERTIES_FILE);
             if (inputStream == null) {
                 String msg = "no pig.properties configuration file available 
in the classpath";
@@ -47,6 +49,8 @@
             }
         } catch (Exception e) {
             log.error("unable to parse pig.properties :", e);
+        } finally {
+            if (inputStream != null) try {inputStream.close();} catch 
(Exception e) {}
         }
 
         Properties pigrcProps = new Properties() ;
@@ -55,10 +59,14 @@
             if (pigrcFile.exists()) {
                 log.warn(pigrcFile.getAbsolutePath()
                         + " exists but will be deprecated soon. Use 
conf/pig.properties instead!");
-                pigrcProps.load(new BufferedInputStream(new 
FileInputStream(pigrcFile))) ;
+
+                bis = new BufferedInputStream(new FileInputStream(pigrcFile));
+                pigrcProps.load(bis) ;
             }
         } catch (Exception e) {
             log.error("unable to parse .pigrc :", e);
+        } finally {
+            if (bis != null) try {bis.close();} catch (Exception e) {}
         }
 
                // Now put all the entries from pigrcProps into properties, but

Modified: 
hadoop/pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java?rev=825712&r1=825711&r2=825712&view=diff
==============================================================================
--- 
hadoop/pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java 
(original)
+++ 
hadoop/pig/trunk/src/org/apache/pig/tools/parameters/PreprocessorContext.java 
Fri Oct 16 00:16:57 2009
@@ -171,9 +171,10 @@
             throw rte;
         }
 
+        BufferedReader br = null;
         try{
             InputStreamReader isr = new InputStreamReader(p.getInputStream());
-            BufferedReader br = new BufferedReader(isr);
+            br = new BufferedReader(isr);
             String line=null;
             while ( (line = br.readLine()) != null){
                 streamData+=(line+"\n");
@@ -181,11 +182,13 @@
         } catch (IOException e){
             RuntimeException rte = new RuntimeException("IO Exception while 
executing shell command : "+e.getMessage() , e);
             throw rte;
+        } finally {
+            if (br != null) try {br.close();} catch(Exception e) {}
         }
-
+       
         try {
             InputStreamReader isr = new InputStreamReader(p.getErrorStream());
-            BufferedReader br = new BufferedReader(isr);
+            br = new BufferedReader(isr);
             String line=null;
             while ( (line = br.readLine()) != null ) {
                 streamError += (line+"\n");
@@ -194,6 +197,8 @@
         } catch (Exception e) {
             RuntimeException rte = new RuntimeException("IO Exception while 
executing shell command : "+e.getMessage() , e);
             throw rte;
+        } finally {
+            if (br != null) try {br.close();} catch(Exception e) {}
         }
 
         return streamData.trim();


Reply via email to