From f3f24f3000274260ab413d65f15915b6050e8bd1 Mon Sep 17 00:00:00 2001 From: lichenyang Date: Fri, 30 Jun 2017 17:24:29 +0800 Subject: [PATCH] =?UTF-8?q?[ZEPPELIN-2713]=20Fix=20NPE=20of=20notebook=20c?= =?UTF-8?q?reat=20rest=20api=20=20if=20message=20is=20nul=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …l or empty ### What is this PR for? Notebook create rest api will cause NPE when the message is null or empty. ### What type of PR is it? [Bug Fix ] ### Todos * [ ] - Task ### What is the Jira issue? * Open an issue on Jira https://issues.apache.org/jira/browse/ZEPPELIN/ * https://issues.apache.org/jira/projects/ZEPPELIN/issues/ZEPPELIN-2713?filter=allopenissues ### How should this be tested? Post to rest api (api/notebook) with nothing, test if NPE ### 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: lichenyang Closes #2457 from reminia/ZEPPELIN-2713 and squashes the following commits: 36e3b46b9 [lichenyang] [ZEPPELIN-2713] Fix NPE of notebook create rest api if message is null or empty --- .../org/apache/zeppelin/rest/NotebookRestApi.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java index 50a8671dcce..e18a2e7f029 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java @@ -332,14 +332,16 @@ public Response importNote(String req) throws IOException { public Response createNote(String message) throws IOException { String user = SecurityUtils.getPrincipal(); LOG.info("Create new note by JSON {}", message); - NewNoteRequest request = gson.fromJson(message, NewNoteRequest.class); AuthenticationInfo subject = new AuthenticationInfo(user); Note note = notebook.createNote(subject); - List initialParagraphs = request.getParagraphs(); - if (initialParagraphs != null) { - for (NewParagraphRequest paragraphRequest : initialParagraphs) { - Paragraph p = note.addNewParagraph(subject); - initParagraph(p, paragraphRequest, user); + NewNoteRequest request = gson.fromJson(message, NewNoteRequest.class); + if (request != null) { + List initialParagraphs = request.getParagraphs(); + if (initialParagraphs != null) { + for (NewParagraphRequest paragraphRequest : initialParagraphs) { + Paragraph p = note.addNewParagraph(subject); + initParagraph(p, paragraphRequest, user); + } } } note.addNewParagraph(subject); // add one paragraph to the last