Skip to content

Primitive array form fields throw ClassCastException during encoding #3607

Closed

Description

@hutiefang76

When a form field value is a primitive array, form encoding tests isArray() and then casts the value to Object[]. For int[] and other primitive arrays, that cast throws ClassCastException.

Reproducer on current master 301ed2a:

RequestTemplate template = new RequestTemplate();
template.header("Content-Type", "application/x-www-form-urlencoded");
new FormEncoder().encode(Collections.singletonMap("ids", new int[] {1, 2}), Map.class, template);

Expected body: ids=1&ids=2, following the existing reference-array behavior. Actual: ClassCastException in UrlencodedFormContentProcessor. With multipart/form-data, ManyParametersWriter.isApplicable fails on the same cast before writer selection can complete.

The same input appears through primitive-array fields in form POJOs. It is distinct from #3586's top-level POJO classification and #3436's escaping of collection values.

A bounded fix reads array elements through java.lang.reflect.Array. URL-encoded values continue to follow CollectionFormat; multipart numeric and boolean arrays become repeated scalar parts. Multipart byte[] must retain its existing single binary part through ByteArrayWriter. No change to Character multipart support or streaming APIs is proposed.

Regression coverage exercises FormEncoder itself, all eight primitive array kinds for URL encoding, multipart repeated values, and exact binary byte[] preservation.

AI assistance: DeepSeek assisted investigation, implementation and regression tests; Codex coordinated verification.

Validation: with the original source, the focused regression tests fail on primitive-array ClassCastException; all 24 focused tests pass with the patch.

Activity

  1. added a commit that references this issue on Oct 8, 2026
    b7da46e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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