Skip to content

[api] Do not ask an immutable partitionOptions list whether it contains null - #9885

Closed
sundapeng wants to merge 1 commit into
apache:masterfrom
sundapeng:fix/create-partitions-immutable-partition-options
Closed

sundapeng wants to merge 1 commit into
apache:masterfrom
sundapeng:fix/create-partitions-immutable-partition-options

Conversation

@sundapeng

Copy link
Copy Markdown
Member

Purpose

CreatePartitionsRequest validates its partitionOptions with

checkArgument(
        partitionOptions == null || !partitionOptions.contains(null),
        "partitionOptions must not contain null maps.");

List.of(...) rejects null queries, so contains(null) throws NullPointerException instead of returning false. A caller that passes a perfectly valid immutable list therefore gets an NPE out of the guard whose job is to explain what is wrong with the argument, and the stack points into ImmutableCollections, not at the request:

new CreatePartitionsRequest(
        List.of(Map.of("dt", "20260916")),
        true,
        null,
        null,
        List.of(Map.of("path", "oss://bucket/archive/dt=20260916")));
java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:222)
	at java.base/java.util.ImmutableCollections$AbstractImmutableList.indexOf(ImmutableCollections.java:170)
	at java.base/java.util.ImmutableCollections$AbstractImmutableList.contains(ImmutableCollections.java:201)
	at org.apache.paimon.rest.requests.CreatePartitionsRequest.<init>(CreatePartitionsRequest.java:109)
	at org.apache.paimon.rest.RESTApi.createPartitions(RESTApi.java:1051)

Found while writing a test that registers a Format Table partition at a custom location through RESTApi.createPartitions. The server side is unaffected — Jackson deserializes into an ArrayList — so this only bites Java clients and test fixtures that build the list with List.of.

Tests

RESTApiJsonTest#createPartitionsRequestAcceptsImmutablePartitionOptionsTest covers both directions: an immutable list of options is accepted and round-trips, and a list that really does hold a null map still fails with the intended IllegalArgumentException and message. It fails with the NPE above on master and passes with this change.

API and Format

No. The accepted inputs and the rejection message are unchanged; only a valid input that used to throw the wrong exception now works.

Documentation

No.

…ns null

CreatePartitionsRequest validates partitionOptions with contains(null), and
List.of answers that with a NullPointerException rather than false. A caller
handing over a valid immutable list therefore gets an NPE from the guard whose
job is to give it a clear message, with a stack that points at the collection
instead of at the argument. Ask with a null-safe stream instead.
@sundapeng sundapeng closed this Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant