Repository: zeppelin Updated Branches: refs/heads/master 214737574 -> eb84aa22d
[ZEPPELIN-1186] Prevent NPE when unbind interpreter ### What is this PR for? Unbinding interpreter from note throws NPE when paragraph repl is not set. ### What type of PR is it? Bug Fix ### What is the Jira issue? [ZEPPELIN-1186](https://issues.apache.org/jira/browse/ZEPPELIN-1186) ### How should this be tested? 1. Create notebook 2. type '%fake ' including space at the end 3. Unbind spark interpreter from note binding and hit save 4. Unbind all interpreter and hit save 5. See if you can save the interpreter bind without error ### Screenshots (if appropriate) **Before**  **After**  ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: Mina Lee <[email protected]> Closes #1191 from minahlee/ZEPPELIN-1186 and squashes the following commits: d65cd83 [Mina Lee] Prevent NPE when unbind interpreter Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/eb84aa22 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/eb84aa22 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/eb84aa22 Branch: refs/heads/master Commit: eb84aa22dcb8de57dfacacfe35d8478e07dc7012 Parents: 2147375 Author: Mina Lee <[email protected]> Authored: Fri Jul 15 18:06:50 2016 +0900 Committer: Mina Lee <[email protected]> Committed: Mon Jul 18 12:25:24 2016 +0900 ---------------------------------------------------------------------- .../helium/HeliumApplicationFactory.java | 3 ++- .../helium/HeliumApplicationFactoryTest.java | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/eb84aa22/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumApplicationFactory.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumApplicationFactory.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumApplicationFactory.java index e051488..e8ebfed 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumApplicationFactory.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/helium/HeliumApplicationFactory.java @@ -445,7 +445,8 @@ public class HeliumApplicationFactory implements ApplicationEventListener, Noteb Interpreter currentInterpreter = p.getCurrentRepl(); List<InterpreterInfo> infos = setting.getInterpreterInfos(); for (InterpreterInfo info : infos) { - if (info.getClassName().equals(currentInterpreter.getClassName())) { + if (currentInterpreter != null && + info.getClassName().equals(currentInterpreter.getClassName())) { onParagraphRemove(p); break; } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/eb84aa22/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java index 4f62324..0af6aca 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/helium/HeliumApplicationFactoryTest.java @@ -240,6 +240,27 @@ public class HeliumApplicationFactoryTest implements JobListenerFactory { notebook.removeNote(note1.getId(), null); } + @Test + public void testInterpreterUnbindOfNullReplParagraph() throws IOException { + // create note + Note note1 = notebook.createNote(null); + + // add paragraph with invalid magic + Paragraph p1 = note1.addParagraph(); + p1.setText("%fake "); + + // make sure that p1's repl is null + Interpreter intp = p1.getCurrentRepl(); + assertEquals(intp, null); + + // Unbind all interpreter from note + // NullPointerException shouldn't occur here + notebook.bindInterpretersToNote(note1.id(), new LinkedList<String>()); + + // remove note + notebook.removeNote(note1.getId(), null); + } + @Test public void testUnloadOnInterpreterRestart() throws IOException {
