Native build issue with Java java.io.ObjectInputStream.readObject

Im trying to build my quarkus application in native mode using a dependency called EsperTech, and there is a specific snippet of code that after countless hours of debugging I discover that is causing issues for me. Basically it deals with some bytes being written to a buffer and read just after it (where it causes the following error).

java.io.InvalidClassException: my.package.CustomConfigurationClass; no valid constructor

The snippet of code is this one (I adapted to code to kotlin):

import com.espertech.esper.common.internal.util.SimpleByteArrayOutputStream
import com.espertech.esper.common.internal.util.ObjectInputStreamWithTCCL
import my.package.CustomConfigurationClass
import java.io.IOException
import java.io.ObjectInputStream
import java.io.ObjectOutputStream

fun <T> copy(configObj: T): T {
    val fbos = SimpleByteArrayOutputStream()
    val outStream = ObjectOutputStream(fbos)
    try {
        outStream.writeObject(orig)
        outStream.flush()
    } finally {
        outStream.close()
    }
    // ...

    val inStream: ObjectInputStream = ObjectInputStreamWithTCCL(fbos.inputStream)
    inStream.readObject() // Where the error happens
}

As you can see it throws exactly in the readObject function, I already checked, and yes, the buffer was properly saved before trying to read from it.

As the error suggests I try to make my class ready for native mode like this (worked for serialization when doing request/response apis, but not for this case, when working with java.io library).

@RegisterForReflection
@kotlinx.serialization.Serializable
data class CustomConfigurationClass(
    val name: String = "CustomConfigurationClass",
) : Serializable {
    constructor() : this("CustomConfigurationClass") // I know I do not need this but I try it to ensure either way
}

Is there any other way to handle this kind of serialization issues with the java.io std library?
I am assuming that this is the issue btw, but it can also be something else.

I tried to exclude this piece of code together with the java.io library from the native build using:

gradle build -x test -Dquarkus.package.type=native -Dquarkus.native.additional-build-args="--initialize-at-run-time=java.io\,<esper_package>\,etc"

But also no luck.

Solved!

I used the same solution posted here: Quarkus hibernate Exception in native mode

My serialization-config.json file:

[
  {"name":"java.io.ObjectInputStream"},
  {"name":"java.io.ObjectOutputStream"},
  {"name":"java.lang.String"},
  {"name":"my.custom.package.config.ConfigurationCustom"},
  ... Other esper library package
]

Every time I re-executed the native build I got this error messages:

Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: SerializationConstructorAccessor class not found for declaringClass: com.espertech.esper.common.client.configuration.compiler.ConfigurationCompilerLanguage (targetConstructorClass: java.lang.Object). Usually adding com.espertech.esper.common.client.configuration.compiler.ConfigurationCompilerLanguage to serialization-config.json fixes the problem.

And just by following the suggestions (adding more packages to the serialization-config.json) I was able to execute successfully.

The only downside is to build every single time just to spot one more class/package to add in my json file, but this is how I manage to solve for now.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật