-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonProvider
: Support specifying the classloader used to resolve the JsonProvider
or support specifying the JsonProvider
implementation
#163
Comments
JsonProvider
used by the Elasticsearch Java ClientJsonProvider
used by the Elasticsearch Java Client via the SPI API
JsonProvider
used by the Elasticsearch Java Client via the SPI APIJsonProvider
: Support specifying the classloader used to resolve the JsonProvider
or support specifying the JsonProvider
implementation
…stead of the new elasticsearch-java waiting for the fix elastic/elasticsearch-java#163
It appears Jenkins made a deliberate choice of not following this rule (see "Context class loader" in the Jenkins plugin development docs and JENKINS-58130). So setting the context classloader in the entry points of your plugin (and restoring it when leaving) should solve the issue. That being said, it's likely that Jenkins isn't the only misbehaving application and the workaround you suggest of falling back to the Elasticsearch client's classloader will certainly solve most issues. We'll add that. However I don't think the complexity added by allowing to set the classloader is needed as it will most always be that of the client. If ever another classloader needs to be set, users can still set the thread's context classloader. Finally, we do value your suggestions and would appreciate that you avoid "I would like" and express them as what they are, suggestions that start a conversation. Thanks. |
Hi ya Using the elastic search client class loader should work fine. Do you have a reference for a well behaved application should set the context classloader? From my understanding it’s the other way around you should not rely on it at all. Ref: https://stackoverflow.com/a/36228195 |
The
jakarta.json.spi.JsonProvider
used by the Elasticsearch Java Client is resolved using thejakarta.json.spi.JsonProvider#provider()
method which unfortunately relies on thejava.util.ServiceLoader#load(java.lang.Class<S>)
API without search in the classloader that loaded the Elasticsearch Java Client (java.util.ServiceLoader#load(java.lang.Class<S>, java.lang.ClassLoader)
).In runtimes like Jenkins, this fails with
ClassNotFoundException: org.glassfish.json.JsonProviderImpl
.I would like the Elasticsearch Java client to either search the
jakarta.json.spi.JsonProvider
in the classloader that Elasticsearch Java Client classes or to support manually setting it.I like very much the pattern chosen by OpenTelemetry with
io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder#setServiceClassLoader()
https://github.com/open-telemetry/opentelemetry-java/blob/v1.11.0/sdk-extensions/autoconfigure/src/main/java/io/opentelemetry/sdk/autoconfigure/AutoConfiguredOpenTelemetrySdkBuilder.java#L283-L289
See
elasticsearch-java/java-client/src/main/java/co/elastic/clients/json/jackson/JsonValueParser.java
Line 39 in 74164d8
The text was updated successfully, but these errors were encountered: