Inclusion of a third-party dependency results in a NPE when creating an Event
opened this issue · comments
Describe the bug
The inclusion of other third-party dependencies can result in the datadog-api-client
not functioning.
To Reproduce
Steps to reproduce the behaviour:
- Clone https://github.com/scottmuc-cp/datadog-api-client-bug-report
- Update line 22 of
DataDogExample.java
with a real API key (not necessary to replicate the issue but obviously would be necessary to see the expected result) - Run
./gradlew run
./gradlew run
> Task :run FAILED
Exception in thread "main" javax.ws.rs.ProcessingException: java.lang.NullPointerException
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:603)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:440)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:62)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.post(ClientInvocationBuilder.java:219)
at com.datadog.api.v1.client.ApiClient.sendRequest(ApiClient.java:1456)
at com.datadog.api.v1.client.ApiClient.invokeAPI(ApiClient.java:1399)
at com.datadog.api.v1.client.api.EventsApi.createEventWithHttpInfo(EventsApi.java:113)
at com.datadog.api.v1.client.api.EventsApi.createEvent(EventsApi.java:65)
at DataDogExample.main(DataDogExample.java:40)
Caused by: java.lang.NullPointerException
at org.glassfish.jersey.client.filter.EncodingFilter.getSupportedEncodings(EncodingFilter.java:108)
at org.glassfish.jersey.client.filter.EncodingFilter.filter(EncodingFilter.java:82)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:590)
... 8 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/Users/summer/homebrew/Cellar/openjdk@11/11.0.12/libexec/openjdk.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 6s
2 actionable tasks: 2 executed
Expected behaviour
The printed output of the EventCreateResponse
:
class EventCreateResponse {
alertType: null
dateHappened: null
deviceName: null
host: null
id: null
payload: null
priority: null
relatedEventId: null
sourceTypeName: null
status: ok
tags: null
text: null
title: null
url: null
}
and the event is visible in the Event Stream.
To see expected behaviour:
- Comment out line 12 of
build.gradle
. - Run
./gradlew run
Environment and Versions (please complete the following information):
- version
1.4.0
of this project. - tested on macOS with
openjdk@11
Additional context
The NullPointerException is occurring here.
I don't quite understand why the inclusion of a different library would result in the dependency injection not fulfilling its task.
Below are the different dependencies graphs based on the inclusion of the keycloak dependency:
with_keycloak.dependencies.txt
without_keycloak.dependencies.txt
This feels like it might be related to #1179
Hi,
I'm not sure it would be solved by shading, as it's a runtime configuration by jboss resteasy which seems to mess up the datadog client. This is worked around by setting the client explicitely:
import org.glassfish.jersey.client.JerseyClientBuilder;
import javax.ws.rs.client.Client;
...
Client client = new JerseyClientBuilder().build();
defaultClient.setHttpClient(client);
Now unfortunately it seems to fail later on some other jackson errors. I'll look into those.
Ah, if you do:
JerseyClientBuilder builder = new JerseyClientBuilder().withConfig(defaultClient.getClientConfig());
Client client = builder.build();
It seems to work as expected.
@therve wow, thank your for the quick response! I'll play around with this for a bit in the non-trivial codebase I'm working on and see how it goes. It did seem like a kind of issue where "I'm doing it wrong", but it was hard for me to tease things out from things not working but just adding a dependency.
OK, thanks @therve. In https://github.com/scottmuc-cp/datadog-api-client-bug-report/commit/bf2905447e4775de9e23aff634eeeea886c0df28 I see it work with all our project dependencies. I feel comfortable closing this issue since it's not a bug in the datadog client. For me personally, I need to read up on how all this stuff gets wired and what resources and messages nudged you towards setting the client explicitly?
Is this something that possibly needs to be documented? Or is this something one knows when using jersey
or resteasy
?