Index: ql/src/java/org/apache/hadoop/hive/ql/parse/EximUtil.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/EximUtil.java (revision 1626924) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/EximUtil.java (working copy) @@ -169,7 +169,8 @@ public static void createExportDump(FileSystem fs, Path metadataPath, org.apache.hadoop.hive.ql.metadata.Table tableHandle, List partitions) throws SemanticException, IOException { - try { + OutputStream out = null; + try { JSONObject jsonContainer = new JSONObject(); jsonContainer.put("version", METADATA_FORMAT_VERSION); if (METADATA_FORMAT_FORWARD_COMPATIBLE_VERSION != null) { @@ -192,12 +193,19 @@ ErrorMsg.GENERIC_ERROR .getMsg("Exception while serializing the metastore objects"), e); } - OutputStream out = fs.create(metadataPath); + out = fs.create(metadataPath); out.write(jsonContainer.toString().getBytes("UTF-8")); - out.close(); } catch (JSONException e) { throw new SemanticException(ErrorMsg.GENERIC_ERROR.getMsg("Error in serializing metadata"), e); + } finally { + try { + if (out != null) { + out.close(); + } + } catch (IOException ioe) { + throw new SemanticException(ErrorMsg.GENERIC_ERROR.getMsg("Error in closing OutputStream"), ioe); + } } }