Skip to content

Fix NPE in MetricsRequestEventListener when @PreMatching ContainerRequestFilter throws exception#159

Open
Fabio Hecht (fabiohecht) wants to merge 1 commit intoconfluentinc:masterfrom
fabiohecht:fix-NPE-throwing-from-prematching
Open

Fix NPE in MetricsRequestEventListener when @PreMatching ContainerRequestFilter throws exception#159
Fabio Hecht (fabiohecht) wants to merge 1 commit intoconfluentinc:masterfrom
fabiohecht:fix-NPE-throwing-from-prematching

Conversation

@fabiohecht

I registered a @PreMatching ContainerRequestFilter via kafka.rest.resource.extension.class and sometimes need to throw exceptions that are mapped to responses. This works fine (client gets the correct response), but the MetricsRequestEventListener logs a NPE.

Root cause: The event RequestEvent.Type.MATCHING_START is never invoked in this case (exception is thrown in PreMatching filter), thus never initializing the wrappedRequestStream field. Later, handling the FINISHED event assumes wrappedRequestStream is set, throwin the NPE.

I believe MetricsRequestEventListener must be patched to initialize the wrappedRequestStream and started without depending on MATCHING_START event, because in this case it is never triggered.

This PR simply replaces the condition if (event.getType() == RequestEvent.Type.MATCHING_START) by if (started == 0L) or if (wrappedRequestStream == null) (at https://github.com/confluentinc/rest-utils/blob/5.3.1-post/core/src/main/java/io/confluent/rest/metrics/MetricsResourceMethodApplicationListener.java#L301) to initialize variables the first time any event is triggered.

….Type.MATCHING_START being triggered (happens when exception thrown from PreMatching request filter).
@ghost
Copy link

It looks like Fabio Hecht (@fabiohecht) hasn't signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement here.

Once you've signed reply with [clabot:check] to prove it.

Appreciation of efforts,

clabot

@fabiohecht Fabio Hecht (fabiohecht) marked this pull request as ready for review November 12, 2019 12:55
@fabiohecht
Copy link
Author

[clabot:check]

@ghost
Copy link

Confluent Inc. (@confluentinc) It looks like Fabio Hecht (@fabiohecht) just signed our Contributor License Agreement. 👍

Always at your service,

clabot

@fabiohecht
Copy link
Author

Fix issue #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants