apache/beam · error · IllegalArgumentException
Attempting to call and() on a CoGbkResult apparently not cre
Error message
Attempting to call and() on a CoGbkResult apparently not created by of().
What it means
CoGbkResult.and() is only valid on results created via CoGbkResult.of(), which track nextTestUnionId as they grow. Calling and() on a result constructed directly with the constructor (or after repeated and() calls beyond the schema) breaks that invariant and is rejected.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/join/CoGbkResult.java:362
}
//////////////////////////////////////////////////////////////////////////////
// Methods for directly constructing a CoGbkResult
//
// (for example, creating test data for a transform that consumes a
// CoGbkResult)
/** Returns a new CoGbkResult that contains just the given tag and given data. */
public static <V> CoGbkResult of(TupleTag<V> tag, List<V> data) {
return CoGbkResult.empty().and(tag, data);
}
/**
* Returns a new {@link CoGbkResult} based on this, with the given tag and given data added to it.
*/
public <V> CoGbkResult and(TupleTag<V> tag, List<V> data) {
if (nextTestUnionId != schema.size()) {
throw new IllegalArgumentException(
"Attempting to call and() on a CoGbkResult apparently not created by" + " of().");
}
List<Iterable<?>> valueMap = new ArrayList<>(this.valueMap);
valueMap.add(data);
return new CoGbkResult(
new CoGbkResultSchema(schema.getTupleTagList().and(tag)), valueMap, nextTestUnionId + 1);
}
/** Returns an empty {@link CoGbkResult}. */
public static CoGbkResult empty() {
return new CoGbkResult(
new CoGbkResultSchema(TupleTagList.empty()), new ArrayList<Iterable<?>>());
}
//////////////////////////////////////////////////////////////////////////////
private int nextTestUnionId = 0;
View on GitHub (pinned to 12126d8942)
Solutions
- Build results with CoGbkResult.of(tupleTagList, rawResults) and use and() from there
- If you must append, construct the CoGbkResult yourself with the extended TupleTagList and full valueMap instead of chaining and()
- Verify nextTestUnionId equals schema.size() before calling and()
Example fix
// before CoGbkResult r = new CoGbkResult(schema, valueMap, 0); r = r.and(tag, data); // throws // after CoGbkResult r = CoGbkResult.of(tagList.and(tag), rawValueMap);
Defensive patterns
Strategy: type-guard
Validate before calling
if (nextTestUnionId != schema.size()) { throw new IllegalStateException("Use CoGbkResult.of() before and()"); } Try / catch
try { return result.and(tag, data); } catch (IllegalArgumentException e) { throw new IllegalStateException("CoGbkResult not created via of()", e); } Prevention
- Always use CoGbkResult.of() factory methods
- Avoid direct constructor use in user code
- Track and() call counts against schema size in tests
When it happens
Trigger: Calling and() on a CoGbkResult created with new CoGbkResult(schema, valueMap, nextUnionId) where nextTestUnionId != schema.size(), or chaining and() more times than the base schema allows.
Common situations: Custom pipeline code constructing CoGbkResult instances manually for testing or deserialization and then trying to append tags; framework-internal results (e.g. from raw union decoding) being mutated.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot merge schemas with different numbers of fields. schem
- TupleTag ${tag} corresponds to an empty result, and no defau
- TupleTag ${tag} corresponds to a non-singleton result
- must have at least one input to a KeyedPCollections
- Unsupported type of %s: %s
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/883f3f5b2f1e78ff.
Report an issue: GitHub.