Skip to content

HttpClient throws IllegalArgumentException when no headers are provided #522

@coderabbitai

Description

@coderabbitai

Description

When making HTTP requests with no headers, the Java HttpClient throws an IllegalArgumentException: wrong number, 0, of parameters error.

Stack Trace

Caused by: java.lang.IllegalArgumentException: wrong number, 0, of parameters
    at java.net.http/jdk.internal.net.http.common.Utils.newIAE(Utils.java:326)
    at java.net.http/jdk.internal.net.http.HttpRequestBuilderImpl.headers(HttpRequestBuilderImpl.java:135)
    at java.net.http/jdk.internal.net.http.HttpRequestBuilderImpl.headers(HttpRequestBuilderImpl.java:43)

Expected Behavior

Wirespec should handle requests with no headers gracefully, without throwing an exception.

Current Workaround

Adding a dummy header to ensure the headers array is not empty:

.let { it + arrayOf("test", "value") }

Context

This issue was discovered while integrating the bunq-sdk built on wirespec. The workaround is currently necessary to prevent crashes when no headers are required for the API request.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions