TracerProviderHelper#currentSpan()
throws NPE in some situations
#8254
Milestone
TracerProviderHelper#currentSpan()
throws NPE in some situations
#8254
Environment Details
Problem Description
In some limited cases, the
TracerProviderHelper#currentSpan
method throws a NPE becauseTRACER_PROVIDER
is null whencurrentSpan
is invoked.In at least two situations, customer code uses a custom
TracerProvider
. The static initializer in Helidon'sTracerProviderHelper
class uses service loading to locate and load such implementations, select one, and store a reference to it in theTRACER_PROVIDER
static field.During its own initialization, that custom
TracerProvider
uses logging, and there is a custom logger in place which attempts to get the current span (if any) to add to log messages. And the attempt to get the current span ultimately invokesTracerProviderHelper.currentSpan()
which depends onTRACER_PROVIDER
being non-null.In this scenario, though,
TRACER_PROVIDER
is still null because the static initializer has not yet finished. That triggers the NPE.Although one could argue that the custom
TracerProvider
should not, even indirectly, invoke code that relies onTRACER_PROVIDER
being non-null, this use case (and ones like it) would be difficult to untangle. Helidon could be of help to users in these situations by anticipating and dealing with this edge case.The text was updated successfully, but these errors were encountered: