Repository: zeppelin
Updated Branches:
  refs/heads/branch-0.7 efe2a944c -> 937bd5f74


ZEPPELIN-2108. Livy interpreter job cancellation throws NPE

### What is this PR for?
It happens in some corner cases where output is null when statement is 
cancelled.

### What type of PR is it?
[Bug Fix]

### Todos
* [ ] - Task

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-2108

### How should this be tested?
Tested manually
![livy_cancelled](https://cloud.githubusercontent.com/assets/164491/23003509/2fb0fc9c-f42c-11e6-8cba-ae654a4e5c08.png)
.

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jeff Zhang <zjf...@apache.org>

Closes #2025 from zjffdu/ZEPPELIN-2108 and squashes the following commits:

191b18a [Jeff Zhang] ZEPPELIN-2108. Livy interpreter job cancellation throws NPE

(cherry picked from commit eb88b0b9e7b711c1a2003fe4a91164976fc61fcd)
Signed-off-by: Felix Cheung <felixche...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/937bd5f7
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/937bd5f7
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/937bd5f7

Branch: refs/heads/branch-0.7
Commit: 937bd5f74b62ba26c0fc4a90f38f5480ecc8e7ec
Parents: efe2a94
Author: Jeff Zhang <zjf...@apache.org>
Authored: Tue Feb 14 13:34:38 2017 +0800
Committer: Felix Cheung <felixche...@apache.org>
Committed: Sun Feb 19 10:21:24 2017 -0800

----------------------------------------------------------------------
 .../org/apache/zeppelin/livy/BaseLivyInterprereter.java | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/937bd5f7/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java
----------------------------------------------------------------------
diff --git 
a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java 
b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java
index 98f54d0..92c5f12 100644
--- a/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java
+++ b/livy/src/main/java/org/apache/zeppelin/livy/BaseLivyInterprereter.java
@@ -299,8 +299,14 @@ public abstract class BaseLivyInterprereter extends 
Interpreter {
 
   private InterpreterResult getResultFromStatementInfo(StatementInfo stmtInfo,
                                                        boolean displayAppInfo) 
{
-    if (stmtInfo.output.isError()) {
+    if (stmtInfo.output != null && stmtInfo.output.isError()) {
       return new InterpreterResult(InterpreterResult.Code.ERROR, 
stmtInfo.output.evalue);
+    } else if (stmtInfo.isCancelled()) {
+      // corner case, output might be null if it is cancelled.
+      return new InterpreterResult(InterpreterResult.Code.ERROR, "Job is 
cancelled");
+    } else if (stmtInfo.output == null) {
+      // This case should never happen, just in case
+      return new InterpreterResult(InterpreterResult.Code.ERROR, "Empty 
output");
     } else {
       //TODO(zjffdu) support other types of data (like json, image and etc)
       String result = stmtInfo.output.data.plain_text;
@@ -533,6 +539,10 @@ public abstract class BaseLivyInterprereter extends 
Interpreter {
       return state.equals("available") || state.equals("cancelled");
     }
 
+    public boolean isCancelled() {
+      return state.equals("cancelled");
+    }
+
     private static class StatementOutput {
       public String status;
       public String execution_count;

Reply via email to