[ 
https://issues.apache.org/jira/browse/FLUME-2719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14946761#comment-14946761
 ] 

Gonzalo Herreros commented on FLUME-2719:
-----------------------------------------

Uploaded a patch that will tread an empty body post to the source as invalid 
JSON and return 400 (Invalid request) instead of the current 500 (Internal 
Error NPE).
I think this is important for 2 reasons:
- An empty request probably means there is something wrong in the client side 
(e.g. serializing the request). It probably shouldn't be sent in the first 
place if there are no event but even if somebody wants to use it as a "health 
check" then it should use a properly formatted empty array batch: "[]"
- The difference between 400 and 500 is important not just from the operations 
point of view but for the client: a 400 error shouldn't be retried while a 500 
might be


> NullPointerException not handled in JSONHandler
> -----------------------------------------------
>
>                 Key: FLUME-2719
>                 URL: https://issues.apache.org/jira/browse/FLUME-2719
>             Project: Flume
>          Issue Type: Bug
>          Components: Sinks+Sources
>    Affects Versions: v1.5.1
>            Reporter: Gonzalo Herreros
>            Priority: Minor
>              Labels: easyfix, patch
>         Attachments: FLUME-2719.patch
>
>
> When using an http source with JSONHandler, invalid json is handled correctly 
> and a 400 error is returned.
> However an empty body provokes and unhandled NPE in JSONHandler which returns 
> a 500.
> If should either ignore the request or complain the request is invalid.
>     try {
>       eventList = gson.fromJson(reader, listType);
>     } catch (JsonSyntaxException ex) {
>       throw new HTTPBadRequestException("Request has invalid JSON Syntax.", 
> ex);
>     }
>     for (Event e : eventList) {
>       ((JSONEvent) e).setCharset(charset);
>     }
> The GSON API describes that fromJson returns null when the imput is EOF 
> (which is arguable but documented).
> Flume should check for eventList being null before trying to loop
> Always reproduced in all version



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to