cloudevents / sdk-java

Java SDK for CloudEvents
https://cloudevents.github.io/sdk-java/
Apache License 2.0
400 stars 160 forks source link

Cannot invoke "java.lang.ClassLoader.getParent()" because "this.currentLoader" is null #643

Closed flebastard closed 4 months ago

flebastard commented 4 months ago

Hi, Since cloudevents-core:3.0.0, we are experiencing this error

java.lang.NullPointerException: Cannot invoke "java.lang.ClassLoader.getParent()" because "this.currentLoader" is null
    at java.base/java.util.ServiceLoader$ModuleServicesLookupIterator.hasNext(ServiceLoader.java:1075)
    at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
    at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
    at io.cloudevents.core.provider.CloudEventValidatorProvider.validate(CloudEventValidatorProvider.java:48)
    at io.cloudevents.core.v1.CloudEventBuilder.build(CloudEventBuilder.java:127)

This does not happen every time we use the builder. I suspect a race condition as CloudEventValidatorProvider is a Singleton that relies on the ServiceLoader class which is not thread safe according to its documentation.

Instances of this class are not safe for use by multiple concurrent threads.