Skip to content

[BUG][Java][okhttp] POST request with an empty body results in a NullPointerException #11833

@pg-fine

Description

@pg-fine

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Sending a POST request with an empty body results in a NullPointerException.
This issue exists since version 5.3.1.

Unexpected exception thrown: java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.MediaType$Companion.parse, parameter $this$toMediaTypeOrNull
org.opentest4j.AssertionFailedError: Unexpected exception thrown: java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.MediaType$Companion.parse, parameter $this$toMediaTypeOrNull
openapi-generator version

OpenAPI 5.4.0 and OpenAPI 5.3.1

OpenAPI declaration file content or url

see https://github.com/pg-fine/openapi-post-empty-body-bug

Generation Details

see https://github.com/pg-fine/openapi-post-empty-body-bug

Steps to reproduce

see https://github.com/pg-fine/openapi-post-empty-body-bug

Related issues/PRs

4ecceb1

"* remove default content-type in java okhttp client" is the reason for this bug

Suggest a fix

add a default content-type or allow empty request bodies with empty content-types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions