Skip to content
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

java.lang.ExceptionInInitializerError when using GenericSerde #810

Open
ayoub-benali opened this issue Nov 29, 2023 · 0 comments
Open

java.lang.ExceptionInInitializerError when using GenericSerde #810

ayoub-benali opened this issue Nov 29, 2023 · 0 comments

Comments

@ayoub-benali
Copy link

ayoub-benali commented Nov 29, 2023

Hello,

I generated case classes from an Avro schema file using sbt-avrohugger and I want to use avro4s for generating a kafka Serde because io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde doesn't work with classes that include Shapeless classes.

Initially I tried this:

import org.apache.kafka.common.serialization.Serde
import com.sksamuel.avro4s.kafka.GenericSerde
import com.sksamuel.avro4s.BinaryFormat
import scala.collection.JavaConverters._

implicit val inputSerde: Serde[MyClass] = new GenericSerde[MyClass](BinaryFormat)

val serdeConfig = Map("schema.registry.url" -> "SOME_URL").asJava
inputSerde.configure(serdeConfig, false)

MyClass has a lot of nested classes and I got this error during compilation:

[error] Error while emitting MyClass$
[error] Method too large: MyClass$.<init> ()V

Then I tried invoking SchemaFor like this:

import org.apache.kafka.common.serialization.Serde
import com.sksamuel.avro4s.kafka.GenericSerde
import com.sksamuel.avro4s.BinaryFormat
import com.sksamuel.avro4s.SchemaFor
import scala.collection.JavaConverters._

implicit val myClassSchemaFor: SchemaFor[MyClass] = SchemaFor[MyClass]
implicit val inputSerde: Serde[MyClass] = new GenericSerde[MyClass](BinaryFormat)

val serdeConfig = Map("schema.registry.url" -> "SOME_URL").asJava
inputSerde.configure(serdeConfig, false)

But then I got this error during runtime:

[error]   caused by java.lang.ExceptionInInitializerError
[error]   caused by java.lang.NullPointerException
[error]   sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error]   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[error]   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[error]   java.lang.reflect.Constructor.newInstance(Constructor.java:423)
....

[error]
[error]   CAUSED BY java.lang.ExceptionInInitializerError
[error]   com.sksamuel.avro4s.AvroSchema$.apply(AvroSchema.scala:20)
[error]   com.sksamuel.avro4s.kafka.GenericSerde.<init>(GenericSerde.scala:21)
...

Any idea how to solve or debug this problem ?

These are the main dependencies:

"org.apache.avro"          % "avro"                   % "1.10.2"
"com.sksamuel.avro4s" %% "avro4s-core"  % "4.1.1",
"com.sksamuel.avro4s" %% "avro4s-kafka" % "4.1.1"
"io.confluent"                   % "kafka-streams-avro-serde" % "5.4.5"
"com.chuusai"                  %% "shapeless"     % "2.3.3"

sbt-avrohugger version 2.8.0
scala version: 2.12.18
Thanks

@ayoub-benali ayoub-benali changed the title Method too large when using GenericSerde java.lang.ExceptionInInitializerError when using GenericSerde Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant