gmethvin opened a new issue #2767: ClassCastException when using custom JSON schema URL: https://github.com/apache/pulsar/issues/2767 #### Expected behavior It should be possible to create a custom JSON `Schema` that's not an implementation of `JSONSchema`, so I can use schemas from libraries like https://github.com/sksamuel/pulsar4s. #### Actual behavior I used the `pulsar4s` library, which creates custom schema implementations. I wrote some very simple code like this: ``` import com.sksamuel.pulsar4s._ import com.sksamuel.pulsar4s.circe._ import io.circe.generic.auto._ case class Foo(bar: String, baz: String) val client = PulsarClient("pulsar://localhost:6650") val topic = Topic("persistent://sample/standalone/ns1/b") val producer = client.producer[Foo](ProducerConfig(topic)) ``` Because pulsar4s creates schema instances that aren't `JSONSchema`, I get a `ClassCastException`: ``` java.util.concurrent.CompletionException: java.lang.ClassCastException: com.sksamuel.pulsar4s.circe.package$$anon$1 cannot be cast to org.apache.pulsar.client.impl.schema.JSONSchema at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280) at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:659) at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:632) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1962) at org.apache.pulsar.client.impl.ConnectionPool.lambda$null$4(ConnectionPool.java:196) at java.util.concurrent.CompletableFuture.uniRun(CompletableFuture.java:705) at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java:687) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474) at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1962) at org.apache.pulsar.client.impl.ClientCnx.handleConnected(ClientCnx.java:235) at org.apache.pulsar.common.api.PulsarDecoder.channelRead(PulsarDecoder.java:148) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at org.apache.pulsar.shade.io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) at org.apache.pulsar.shade.io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at org.apache.pulsar.shade.io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1414) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at org.apache.pulsar.shade.io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at org.apache.pulsar.shade.io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:945) at org.apache.pulsar.shade.io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:146) at org.apache.pulsar.shade.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at org.apache.pulsar.shade.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at org.apache.pulsar.shade.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at org.apache.pulsar.shade.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at org.apache.pulsar.shade.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886) at org.apache.pulsar.shade.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassCastException: com.sksamuel.pulsar4s.circe.package$$anon$1 cannot be cast to org.apache.pulsar.client.impl.schema.JSONSchema at org.apache.pulsar.client.impl.ProducerImpl.connectionOpened(ProducerImpl.java:874) at org.apache.pulsar.client.impl.ConnectionHandler.lambda$grabCnx$0(ConnectionHandler.java:65) at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:656) ... 30 more ``` This is due to an unsafe cast at https://github.com/apache/pulsar/blob/v2.1.1-incubating/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java#L874 This was also reported at https://github.com/sksamuel/pulsar4s/issues/6 #### System configuration **Pulsar version**: 2.1.1
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services