ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sneet...@apache.org
Subject incubator-ranger git commit: RANGER-331: inputstream is closed in the finally clause
Date Tue, 24 Mar 2015 14:44:05 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 0ab48758f -> ce139e013


RANGER-331: inputstream is closed in the finally clause


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/ce139e01
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/ce139e01
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/ce139e01

Branch: refs/heads/master
Commit: ce139e013aa4f0e6472ac910b9c62073ed902f35
Parents: 0ab4875
Author: sneethiraj <sneethir@apache.org>
Authored: Tue Mar 24 10:30:21 2015 -0400
Committer: sneethiraj <sneethir@apache.org>
Committed: Tue Mar 24 10:30:21 2015 -0400

----------------------------------------------------------------------
 .../plugin/client/HadoopConfigHolder.java       | 24 ++++++++++-----
 .../ranger/utils/install/XmlConfigChanger.java  | 12 ++++++++
 .../ranger/server/tomcat/EmbeddedServer.java    | 10 ++++++
 .../ranger/services/hdfs/HdfsClientTester.java  | 18 ++++++++++-
 .../services/hive/client/HiveClientTester.java  | 18 ++++++++++-
 .../main/java/org/apache/util/sql/Jisql.java    | 32 ++++++++++++++++++--
 .../java/org/apache/util/sql/MySQLPLRunner.java | 17 +++++++++--
 .../ranger/services/knox/client/KnoxClient.java |  2 +-
 .../ranger/hadoop/client/HadoopFSTester.java    | 17 ++++++++++-
 .../ranger/hbase/client/HBaseClientTester.java  | 18 +++++++++--
 .../config/UserGroupSyncConfig.java             | 13 +++++++-
 .../unix/jaas/RemoteUnixLoginModule.java        | 14 +++++++--
 .../UnixAuthenticationService.java              | 18 +++++++++--
 13 files changed, 191 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
b/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
index a341a44..f95e10e 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/client/HadoopConfigHolder.java
@@ -157,16 +157,26 @@ public class HadoopConfigHolder  {
 			if (in != null) {
 				try {
 					resourcemapProperties.load(in);
-          for (Map.Entry<Object, Object> entry : resourcemapProperties.entrySet() )
{
-            String key = (String)entry.getKey();
-            String value = (String)entry.getValue();
-            if (RANGER_SECTION_NAME.equals(value))  {
-              rangerInternalPropertyKeys.add(key);
-            }
-          }
+		          for (Map.Entry<Object, Object> entry : resourcemapProperties.entrySet()
) {
+		            String key = (String)entry.getKey();
+		            String value = (String)entry.getValue();
+		            if (RANGER_SECTION_NAME.equals(value))  {
+		              rangerInternalPropertyKeys.add(key);
+		            }
+		          }
 				} catch (IOException e) {
 					throw new HadoopException("Unable to load resource map properties from [" + RESOURCEMAP_PROP_FILE
+ "]", e);
 				}
+				finally {
+					if (in != null) {
+						try {
+							in.close() ;
+						}
+						catch(IOException ioe) {
+							// Ignore IOException during close of stream
+						}
+					}
+				}
 			}
 			else {
 				throw new HadoopException("Unable to locate resource map properties from [" + RESOURCEMAP_PROP_FILE
+ "] in the class path.");

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/agents-installer/src/main/java/org/apache/ranger/utils/install/XmlConfigChanger.java
----------------------------------------------------------------------
diff --git a/agents-installer/src/main/java/org/apache/ranger/utils/install/XmlConfigChanger.java
b/agents-installer/src/main/java/org/apache/ranger/utils/install/XmlConfigChanger.java
index f2665ae..05fbb23 100644
--- a/agents-installer/src/main/java/org/apache/ranger/utils/install/XmlConfigChanger.java
+++ b/agents-installer/src/main/java/org/apache/ranger/utils/install/XmlConfigChanger.java
@@ -425,7 +425,19 @@ public class XmlConfigChanger {
 	private void loadInstallProperties() throws IOException {
 		if (propFile != null) {
 			FileInputStream in = new FileInputStream(propFile) ;
+			try {
 			installProperties.load(in);
+			}
+			finally {
+				if (in != null) {
+					try {
+						in.close();
+					}
+					catch(IOException ioe) {
+						// Ignore IOException during close of stream
+					}
+				}
+			}
 		}
 		// To support environment variable, we will add all environment variables to the Properties
 		installProperties.putAll(System.getenv());

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/EmbeddedServer.java
----------------------------------------------------------------------
diff --git a/embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/EmbeddedServer.java
b/embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/EmbeddedServer.java
index 75c80d5..4460aa8 100644
--- a/embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/EmbeddedServer.java
+++ b/embeddedwebserver/src/main/java/org/apache/ranger/server/tomcat/EmbeddedServer.java
@@ -82,6 +82,16 @@ public class EmbeddedServer {
 			LOG.severe("Unable to load config  file [" + cfgFile + "]");
 			ioe.printStackTrace(); 
 		}
+		finally {
+			if (in != null) {
+				try {
+					in.close() ;
+				}
+				catch(IOException ioe) {
+					// Ignore IOE when the stream is closed.
+				}
+			}
+		}
 		serverConfigProperties.list(System.out);
 	}
 	

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HdfsClientTester.java
----------------------------------------------------------------------
diff --git a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HdfsClientTester.java
b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HdfsClientTester.java
index 3947ac2..2e8290c 100644
--- a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HdfsClientTester.java
+++ b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/HdfsClientTester.java
@@ -19,6 +19,8 @@
 
  package org.apache.ranger.services.hdfs;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
@@ -39,7 +41,21 @@ public class HdfsClientTester {
 		String fileNameToMatch = (args.length == 3 ? null : args[3]) ;
 
 		Properties conf = new Properties() ;
-		conf.load(HdfsClientTester.class.getClassLoader().getResourceAsStream(propFile));
+		
+		InputStream in = HdfsClientTester.class.getClassLoader().getResourceAsStream(propFile)
;
+		try {
+			conf.load(in);
+		}
+		finally {
+			if (in != null) {
+				try {
+				in.close() ;
+				}
+				catch(IOException ioe) {
+					// Ignore IOException created during close
+				}
+			}
+		}
 		
 		HashMap<String,String> prop = new HashMap<String,String>() ;
 		for(Object key : conf.keySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/hive-agent/src/test/java/org/apache/ranger/services/hive/client/HiveClientTester.java
----------------------------------------------------------------------
diff --git a/hive-agent/src/test/java/org/apache/ranger/services/hive/client/HiveClientTester.java
b/hive-agent/src/test/java/org/apache/ranger/services/hive/client/HiveClientTester.java
index 9cd1cd0..1ff0f35 100644
--- a/hive-agent/src/test/java/org/apache/ranger/services/hive/client/HiveClientTester.java
+++ b/hive-agent/src/test/java/org/apache/ranger/services/hive/client/HiveClientTester.java
@@ -20,6 +20,8 @@
 package org.apache.ranger.services.hive.client;
  
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
@@ -40,7 +42,21 @@ public class HiveClientTester  {
 		try {
 			
 			Properties conf = new Properties() ;
-			conf.load(HiveClientTester.class.getClassLoader().getResourceAsStream(args[1]));
+			
+			InputStream in = HiveClientTester.class.getClassLoader().getResourceAsStream(args[1])
;
+			try {
+				conf.load(in);
+			}
+			finally {
+				if (in != null) {
+					try {
+						in.close();
+					}
+					catch(IOException ioe) {
+						// Ignore IOException when closing the stream
+					}
+				}
+			}
 			
 			HashMap<String,String> prop = new HashMap<String,String>() ;
 			for(Object key : conf.keySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/jisql/src/main/java/org/apache/util/sql/Jisql.java
----------------------------------------------------------------------
diff --git a/jisql/src/main/java/org/apache/util/sql/Jisql.java b/jisql/src/main/java/org/apache/util/sql/Jisql.java
index c3ba5a6..e5dac9b 100644
--- a/jisql/src/main/java/org/apache/util/sql/Jisql.java
+++ b/jisql/src/main/java/org/apache/util/sql/Jisql.java
@@ -31,8 +31,10 @@ import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Properties;
+
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
+
 import org.apache.util.outputformatter.JisqlFormatter;
 
 /**
@@ -291,8 +293,20 @@ public class Jisql {
             else {
             	if(connectString.toLowerCase().startsWith("jdbc:mysql") && inputFileName!=null){
             		MySQLPLRunner scriptRunner = new MySQLPLRunner(connection, false, true,printDebug);
-            		scriptRunner.setDelimiter(commandTerminator,false);                 	
-                	scriptRunner.runScript(new FileReader(inputFileName));
+            		scriptRunner.setDelimiter(commandTerminator,false);
+            		FileReader reader = new FileReader(inputFileName) ;
+            		try {
+                	scriptRunner.runScript(reader);
+            		}
+            		finally {
+            			if (reader != null) {
+            				try {
+								reader.close();
+							} catch (IOException ioe) {
+								// Ignore error during closing of the reader stream
+							}
+            			}
+            		}
             	}else{
             		doIsql();
             	}
@@ -358,6 +372,9 @@ public class Jisql {
         statement = connection.createStatement();
         connection.clearWarnings();
         String trimmedLine=null;
+        
+        try {
+        
         while (true) {
             int linecount = 1;
             query = new StringBuffer();
@@ -480,6 +497,17 @@ public class Jisql {
             if (inputQuery != null)
                 return;
         }
+        }
+        finally {
+        	if (reader != null) {
+        		try {
+        			reader.close();
+        		}
+        		catch(IOException ioe) {
+        			// Ignore IOE when closing streams
+        		}
+        	}
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/jisql/src/main/java/org/apache/util/sql/MySQLPLRunner.java
----------------------------------------------------------------------
diff --git a/jisql/src/main/java/org/apache/util/sql/MySQLPLRunner.java b/jisql/src/main/java/org/apache/util/sql/MySQLPLRunner.java
index dc5de79..c41c95e 100644
--- a/jisql/src/main/java/org/apache/util/sql/MySQLPLRunner.java
+++ b/jisql/src/main/java/org/apache/util/sql/MySQLPLRunner.java
@@ -31,7 +31,6 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.List;
 import java.util.Properties;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -311,7 +310,21 @@ public class MySQLPLRunner {
     	
     	
     	// Executing SQL Script
-    	scriptRunner.runScript(new FileReader(aSQLScriptFilePath));
+     	FileReader reader = new FileReader(aSQLScriptFilePath) ;
+     	
+     	try {
+     		scriptRunner.runScript(reader);
+     	}
+     	finally {
+     		if (reader != null) {
+     			try {
+     			reader.close();
+     			}
+     			catch(IOException ioe) {
+     				// Ignore IOException when reader is getting closed
+     			}
+     		}
+     	}
 
     	
     	  }

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
----------------------------------------------------------------------
diff --git a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
index 0a23f57..9f7a955 100644
--- a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
+++ b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
@@ -304,7 +304,7 @@ public class KnoxClient {
 										   Map<String, String> configs) {
 		KnoxClient knoxClient = null;
 		LOG.debug("Getting knoxClient for ServiceName: " + serviceName
-				+ "configMap: " + configs.toString());
+				+ "configMap: " + configs);
 		String errMsg = " You can still save the repository and start creating "
 				+ "policies, but you would not be able to use autocomplete for "
 				+ "resource names. Check xa_portal.log for more info.";

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/lookup-client/src/main/java/org/apache/ranger/hadoop/client/HadoopFSTester.java
----------------------------------------------------------------------
diff --git a/lookup-client/src/main/java/org/apache/ranger/hadoop/client/HadoopFSTester.java
b/lookup-client/src/main/java/org/apache/ranger/hadoop/client/HadoopFSTester.java
index 8199971..dc73801 100644
--- a/lookup-client/src/main/java/org/apache/ranger/hadoop/client/HadoopFSTester.java
+++ b/lookup-client/src/main/java/org/apache/ranger/hadoop/client/HadoopFSTester.java
@@ -19,6 +19,8 @@
 
  package org.apache.ranger.hadoop.client;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
@@ -37,7 +39,20 @@ public class HadoopFSTester {
 		String fileNameToMatch = (args.length == 3 ? null : args[3]) ;
 
 		Properties conf = new Properties() ;
-		conf.load(HadoopFSTester.class.getClassLoader().getResourceAsStream(propFile));
+		InputStream in = HadoopFSTester.class.getClassLoader().getResourceAsStream(propFile) ;
+		try {
+			conf.load(in);
+		}
+		finally {
+			if (in != null) {
+				try {
+					in.close() ;
+				}
+				catch(IOException ioe) {
+					// Ignore IOE when closing stream
+				}
+			}
+		}
 		
 		HashMap<String,String> prop = new HashMap<String,String>() ;
 		for(Object key : conf.keySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/lookup-client/src/main/java/org/apache/ranger/hbase/client/HBaseClientTester.java
----------------------------------------------------------------------
diff --git a/lookup-client/src/main/java/org/apache/ranger/hbase/client/HBaseClientTester.java
b/lookup-client/src/main/java/org/apache/ranger/hbase/client/HBaseClientTester.java
index dc177e6..617d2e1 100644
--- a/lookup-client/src/main/java/org/apache/ranger/hbase/client/HBaseClientTester.java
+++ b/lookup-client/src/main/java/org/apache/ranger/hbase/client/HBaseClientTester.java
@@ -19,6 +19,8 @@
 
  package org.apache.ranger.hbase.client;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
@@ -42,8 +44,20 @@ public class HBaseClientTester {
 		LOG.info("Starting ...");
 
 		Properties conf = new Properties();
-		
-		conf.load(HBaseClientTester.class.getClassLoader().getResourceAsStream(args[1]));
+		InputStream in = HBaseClientTester.class.getClassLoader().getResourceAsStream(args[1])
;
+		try {
+		conf.load(in);
+		}
+		finally {
+			if (in != null) {
+				try {
+				in.close();
+				}
+				catch(IOException ioe) {
+					// Ignore IOE when closing stream
+				}
+			}
+		}
 
 		HashMap<String, String> prop = new HashMap<String, String>();
 		for (Object key : conf.keySet()) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
index 6ef27fe..b2c2eb5 100644
--- a/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
+++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/config/UserGroupSyncConfig.java
@@ -22,6 +22,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Properties;
@@ -169,7 +170,17 @@ public class UserGroupSyncConfig  {
 		try {
 			InputStream in = getFileInputStream(CONFIG_FILE) ;
 			if (in != null) {
-				prop.load(in) ;
+				try {
+					prop.load(in) ;
+				}
+				finally {
+					try {
+						in.close() ;
+					}
+					catch(IOException ioe) {
+						// Ignore IOE when closing stream
+					}
+				}
 			}
 		} catch (Throwable e) {
 			throw new RuntimeException("Unable to load configuration file [" + CONFIG_FILE + "]",
e) ;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/unixauthclient/src/main/java/org/apache/ranger/authentication/unix/jaas/RemoteUnixLoginModule.java
----------------------------------------------------------------------
diff --git a/unixauthclient/src/main/java/org/apache/ranger/authentication/unix/jaas/RemoteUnixLoginModule.java
b/unixauthclient/src/main/java/org/apache/ranger/authentication/unix/jaas/RemoteUnixLoginModule.java
index f6564be..0280464 100644
--- a/unixauthclient/src/main/java/org/apache/ranger/authentication/unix/jaas/RemoteUnixLoginModule.java
+++ b/unixauthclient/src/main/java/org/apache/ranger/authentication/unix/jaas/RemoteUnixLoginModule.java
@@ -145,8 +145,18 @@ public class RemoteUnixLoginModule implements LoginModule {
 			try {
 				in = getFileInputStream(val) ;
 				if (in != null) {
-					config = new Properties() ;
-					config.load(in);
+					try {
+						config = new Properties() ;
+						config.load(in);
+					}
+					finally {
+						try {
+							in.close();
+						}
+						catch(IOException ioe) {
+							// Ignore IOException when closing streams
+						}
+					}
 				}
 				
 			}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ce139e01/unixauthservice/src/main/java/org/apache/ranger/authentication/UnixAuthenticationService.java
----------------------------------------------------------------------
diff --git a/unixauthservice/src/main/java/org/apache/ranger/authentication/UnixAuthenticationService.java
b/unixauthservice/src/main/java/org/apache/ranger/authentication/UnixAuthenticationService.java
index 1629e13..01ad7f4 100644
--- a/unixauthservice/src/main/java/org/apache/ranger/authentication/UnixAuthenticationService.java
+++ b/unixauthservice/src/main/java/org/apache/ranger/authentication/UnixAuthenticationService.java
@@ -22,6 +22,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.ServerSocket;
 import java.net.Socket;
@@ -125,9 +126,22 @@ public class UnixAuthenticationService {
 
 	//TODO: add more validation code
 	private void init() throws Throwable {
-		InputStream in = getFileInputStream("unixauthservice.properties") ;
 		Properties prop = new Properties() ;
-		prop.load(in);
+		InputStream in = getFileInputStream("unixauthservice.properties") ;
+
+		if (in != null) {
+			try {
+				prop.load(in);
+			}
+			finally {
+				try {
+					in.close();
+				}
+				catch(IOException ioe) {
+					// Ignore IOE when closing streams
+				}
+			}
+		}
 		keyStorePath = prop.getProperty(SSL_KEYSTORE_PATH_PARAM) ;
 		keyStorePathPassword = prop.getProperty(SSL_KEYSTORE_PATH_PASSWORD_PARAM) ;
 		trustStorePath  = prop.getProperty(SSL_TRUSTSTORE_PATH_PARAM) ;


Mime
View raw message