IFrameWriter.close() can be called if open() failed

Fix potential NPE in ResultWriterOperatorDescriptor should open() fail
and close() be subsequently called

Change-Id: I6f53258765719c30b132bf67680f280924b624be
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1832
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/hyracks-fullstack/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/result/ResultWriterOperatorDescriptor.java b/hyracks-fullstack/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/result/ResultWriterOperatorDescriptor.java
index d3120bb..78417ac 100644
--- a/hyracks-fullstack/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/result/ResultWriterOperatorDescriptor.java
+++ b/hyracks-fullstack/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/result/ResultWriterOperatorDescriptor.java
@@ -117,15 +117,17 @@
 
             @Override
             public void close() throws HyracksDataException {
-                try {
-                    if (!failed && frameOutputStream.getTupleCount() > 0) {
-                        frameOutputStream.flush(datasetPartitionWriter);
+                if (datasetPartitionWriter != null) {
+                    try {
+                        if (!failed && frameOutputStream.getTupleCount() > 0) {
+                            frameOutputStream.flush(datasetPartitionWriter);
+                        }
+                    } catch (Exception e) {
+                        datasetPartitionWriter.fail();
+                        throw e;
+                    } finally {
+                        datasetPartitionWriter.close();
                     }
-                } catch (Exception e) {
-                    datasetPartitionWriter.fail();
-                    throw e;
-                } finally {
-                    datasetPartitionWriter.close();
                 }
             }