Description
Problem:
JsonSerializer and JsonDeserializer use objectMapper.findAndRegisterModules(), which attempts to register all Jackson modules implementing com.fasterxml.jackson.databind.Module. This can cause a ServiceConfigurationError when incompatible modules are present in the classpath.
java.util.ServiceConfigurationError: org.apache.kafka.connect.storage.Converter: Provider org.apache.kafka.connect.json.JsonConverter could not be instantiated at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586) at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:813) at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:729) at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403) at org.apache.kafka.connect.runtime.isolation.PluginScanner.handleLinkageError(PluginScanner.java:176) at org.apache.kafka.connect.runtime.isolation.PluginScanner.getServiceLoaderPluginDesc(PluginScanner.java:136) at org.apache.kafka.connect.runtime.isolation.ServiceLoaderScanner.scanPlugins(ServiceLoaderScanner.java:61) at org.apache.kafka.connect.runtime.isolation.PluginScanner.scanUrlsAndAddPlugins(PluginScanner.java:79) at org.apache.kafka.connect.runtime.isolation.PluginScanner.discoverPlugins(PluginScanner.java:67) at org.apache.kafka.connect.runtime.isolation.Plugins.initLoaders(Plugins.java:99) at org.apache.kafka.connect.runtime.isolation.Plugins.<init>(Plugins.java:90) at org.apache.kafka.connect.runtime.isolation.Plugins.<init>(Plugins.java:78) at org.apache.kafka.connect.cli.AbstractConnectCli.startConnect(AbstractConnectCli.java:128) at org.apache.kafka.connect.cli.AbstractConnectCli.run(AbstractConnectCli.java:101) at org.apache.kafka.connect.cli.ConnectDistributed.main(ConnectDistributed.java:113) Caused by: java.util.ServiceConfigurationError: com.fasterxml.jackson.databind.Module: com.fasterxml.jackson.datatype.jsr310.JavaTimeModule not a subtype at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1244) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273) at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309) at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393) at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1158) at com.fasterxml.jackson.databind.ObjectMapper.findModules(ObjectMapper.java:1142) at com.fasterxml.jackson.databind.ObjectMapper.findAndRegisterModules(ObjectMapper.java:1192) at org.apache.kafka.connect.json.JsonSerializer.<init>(JsonSerializer.java:58) at org.apache.kafka.connect.json.JsonConverter.<init>(JsonConverter.java:250) at org.apache.kafka.connect.json.JsonConverter.<init>(JsonConverter.java:238) at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:789) ... 13 more
Steps to Reproduce:
1. Start a connect worker with Service loading enabled and with certain connector plugins in plugin path (e.g. AzureBlobSource & BigQuerySink)
2. Observe ServiceConfigurationError during plugin discovery
Current Behavior:
ServiceConfigurationError is thrown with message "com.fasterxml.jackson.databind.Module: <module-name> not a subtype"
Where <module-name> can be one of: -
- com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule
- com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
- com.fasterxml.jackson.datatype.guava.GuavaModule
- com.fasterxml.jackson.datatype.joda.JodaModule
Proposed Solution:
Explicitly register the Afterburner module instead of using findAndRegisterModules().
Potential Impact:
- Resolves compatibility issues with certain Jackson modules
- Maintains performance improvements from Afterburner module
- May slightly change behavior for users relying on auto-registration of other Jackson modules
Attachments
Issue Links
- is caused by
-
KAFKA-15996 json serializer too slow
- Resolved
- relates to
-
KAFKA-17117 Avoid instantiating classpath plugins when service loading plugins
- Open
- links to