This is an automated email from the ASF dual-hosted git repository.

zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new 320bb43  [ZEPPELIN-5174]. NPE in SparkSqlInterpreter
320bb43 is described below

commit 320bb43d941f37d692605474e893dc30bab0a281
Author: Jeff Zhang <[email protected]>
AuthorDate: Wed Jan 6 13:46:53 2021 +0800

    [ZEPPELIN-5174]. NPE in SparkSqlInterpreter
    
    ### What is this PR for?
    
    The exception in SparkSqlInterpreter may not have cause, so this PR is to 
fix the NPE via checking whether the cause is null.
    
    ### What type of PR is it?
    [Bug Fix]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5174
    
    ### How should this be tested?
    * CI pass
    
    ### Screenshots (if appropriate)
    
    ### Questions:
    * Does the licenses files need update? No
    * Is there breaking changes for older versions? No
    * Does this needs documentation? No
    
    Author: Jeff Zhang <[email protected]>
    
    Closes #4003 from zjffdu/ZEPPELIN-5174 and squashes the following commits:
    
    c486e7265 [Jeff Zhang] use parameteried method in logging
    31ead8c20 [Jeff Zhang] [ZEPPELIN-5174]. NPE in SparkSqlInterpreter
    
    (cherry picked from commit 731a9998812916cd3d99912f064804e002a3e14c)
    Signed-off-by: Jeff Zhang <[email protected]>
---
 .../apache/zeppelin/spark/SparkSqlInterpreter.java    | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git 
a/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java
 
b/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java
index 4161f1a..cd82878 100644
--- 
a/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java
+++ 
b/spark/interpreter/src/main/java/org/apache/zeppelin/spark/SparkSqlInterpreter.java
@@ -115,14 +115,23 @@ public class SparkSqlInterpreter extends 
AbstractInterpreter {
           context.out.flush();
           return new InterpreterResult(Code.ERROR);
         } else {
+          LOGGER.error("Error happens in sql: {}", curSql, e);
           context.out.write("\nError happens in sql: " + curSql + "\n");
           if 
(Boolean.parseBoolean(getProperty("zeppelin.spark.sql.stacktrace", "false"))) {
-            context.out.write(ExceptionUtils.getStackTrace(e.getCause()));
+            if (e.getCause() != null) {
+              context.out.write(ExceptionUtils.getStackTrace(e.getCause()));
+            } else {
+              context.out.write(ExceptionUtils.getStackTrace(e));
+            }
           } else {
-            LOGGER.error("Invocation target exception", e);
-            String msg = e.getCause().getMessage()
-                    + "\nset zeppelin.spark.sql.stacktrace = true to see full 
stacktrace";
-            context.out.write(msg);
+            StringBuilder msgBuilder = new StringBuilder();
+            if (e.getCause() != null) {
+              msgBuilder.append(e.getCause().getMessage());
+            } else {
+              msgBuilder.append(e.getMessage());
+            }
+            msgBuilder.append("\nset zeppelin.spark.sql.stacktrace = true to 
see full stacktrace");
+            context.out.write(msgBuilder.toString());
           }
           context.out.flush();
           return new InterpreterResult(Code.ERROR);

Reply via email to