square / square/wire

Ignore null lists in MessageJsonAdapter#fromJson

Open
#3,353 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

In MessageJsonAdapter#fromJson, we ignore null values with if (value == null) continue. But if the deserialized value is a List<T?> whose some element is null, we still call fieldBinding.set(builder, value).

Image

Later, when the T message is built, immutableCopyOf("…", list) checks require(null !in result) and throws an IllegalArgumentException because the list contains a null entry.

Image

Is it okay to open a PR that updates fromJson to skip lists where every element is null, or to only include non-null elements?

EDIT: I initially thought we could simply remove nulls, but there are cases—like repeated google.protobuf.NullValue—where null is officially permitted.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at MessageJsonAdapter#fromJson and trace how deserialized lists are passed to fieldBinding.set when they contain null elements. Check the existing handling of repeated google.protobuf.NullValue before deciding the intended behavior, then add regression coverage showing that valid null values remain supported and other null-list cases no longer fail during message construction.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.