Skip to content

[BUG] Runtime crash when serializing AsyncApi without mandatory fields #228

@Varadraj75

Description

@Varadraj75

Describe the bug.

The AsyncApi DSL allows creating an instance without initializing mandatory fields such as info and channels.
This leads to a runtime crash during JSON serialization, instead of failing fast with a clear validation error.

The issue occurs because these mandatory fields are defined using lateinit, which bypasses compile-time checks and throws an exception only when accessed at runtime.

Expected behavior

  • The AsyncApi DSL should fail fast when mandatory fields such as info and channels are not defined.
  • A clear, descriptive validation error should be thrown, indicating which required fields are missing.
  • The error should occur before or during DSL validation, not later during JSON serialization.
  • Runtime crashes caused by lateinit access should be avoided.
  • Users should not be able to generate or serialize an invalid AsyncAPI document.

Screenshots

Failing test output when running mvn -pl kotlin-asyncapi-core test:

Image

This shows a runtime failure caused by accessing an uninitialized lateinit property
(AsyncApi["info"]) during Jackson serialisation.

How to Reproduce

  1. Clone the repository:
    git clone https://github.com/asyncapi/kotlin-asyncapi.git
    cd kotlin-asyncapi
  2. Add code that creates an AsyncApi instance without setting required fields and serialise it:
    val asyncApi = AsyncApi()
    ObjectMapper().writeValueAsString(asyncApi)
  3. Run the core module tests:
    mvn -pl kotlin-asyncapi-core test
  4. The build fails with:
    lateinit property info has not been initialized
    
    

🖥️ Device Information [optional]

  • Operating System (OS): macOS
  • Browser: Google Chrome
  • Browser Version: 144.0.0.0

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions