[ZEPPELIN-6012] Fix NPE when the run-note request body carries no params - #5385
Open
big-cir wants to merge 1 commit into
Open
[ZEPPELIN-6012] Fix NPE when the run-note request body carries no params#5385big-cir wants to merge 1 commit into
big-cir wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR for?
POST /api/notebook/job/{noteId}accepts an optional request body carrying form parameters. Sending a body that supplies no parameters, either{}or{"params":null}, returns HTTP 500.ParametersRequestdeclares itsparamsfield asfinaland assigns it in the constructor, but Gson never invokes that constructor. It allocates the instance and fills the fields reflectively, so a body without a"params"entry leaves the field at its default value ofnull.NotebookRestApi.runNoteJobsthen hands thatnullstraight toHashMap.putAll:{}is not an empty string, so the guard passes and the call throws:Nothing catches it, so
WebApplicationExceptionMapperturns it into a genericInternal server errorwith status 500. Running a note without form parameters is a legitimate request, and an empty body already works, so both spellings should behave the same.This PR makes
ParametersRequest.getParams()return an empty map instead ofnull, which covers both an absent key and an explicit null value.Scope note: two other call sites parse the same request object, at
NotebookRestApilines 979 and 1018. Both assign the result to a local variable rather than callingputAll, so they do not throw, and their consumers already guard against null (Note.runAllSyncandNotebookService.runParagrapheach checkparams != null && !params.isEmpty()). Fixing the accessor covers all three call sites without changing their behavior.What type of PR is it?
Bug Fix
Todos
ParametersRequest.getParams()when no parameters were supplied{}and{"params":null}What is the Jira issue?
How should this be tested?
New test
NotebookRestApiTest#testRunNoteWithoutParamsInBodycreates a note and posts both bodies to the run-note endpoint, asserting that each returns statusOK../mvnw package -pl zeppelin-server --am \ -Dtest='NotebookRestApiTest#testRunNoteWithoutParamsInBody' -DfailIfNoTests=falseReverting only the production change makes the new test fail with
Expected: HTTP response <200> but: got <500>, and the server log shows the stack trace above. With the fix it passes.Also verified by hand against a locally running server, posting each body to
/api/notebook/job/{noteId}:{}{"params":null}{"params":{"name":"zeppelin"}}Screenshots (if appropriate)
N/A
Questions: