alibaba/nacos · error · UnsupportedOperationException
Can't get single data from batched data.
Error message
Can't get single data from batched data.
What it means
Thrown as UnsupportedOperationException by AgentEndpointWrapper.getData() when the wrapper was created in batch mode (via wrap(Collection<AgentEndpoint>)). getData() is the single-item accessor and is only valid on wrappers created via wrap(AgentEndpoint). This is a programming error indicating a type/access-pattern mismatch.
Source
Thrown at client/src/main/java/com/alibaba/nacos/client/ai/remote/redo/AgentEndpointWrapper.java:57
this.data = copyEndpoints(data);
this.isBatch = isBatch;
}
public static AgentEndpointWrapper wrap(AgentEndpoint data) {
return new AgentEndpointWrapper(Collections.singletonList(data), false);
}
public static AgentEndpointWrapper wrap(Collection<AgentEndpoint> data) {
return new AgentEndpointWrapper(data, true);
}
public boolean isBatch() {
return isBatch;
}
public AgentEndpoint getData() {
if (isBatch) {
throw new UnsupportedOperationException("Can't get single data from batched data.");
}
return data.iterator().next();
}
public Collection<AgentEndpoint> getBatchData() {
if (!isBatch) {
throw new UnsupportedOperationException("Can't get batched data from single data.");
}
return data;
}
/**
* Return the exact Agent Version shared by this wrapper's Endpoint payload.
*
* @return exact Version
*/
public String getVersion() {
return data.iterator().next().getVersion();View on GitHub (pinned to 9b989acdf1)
Solutions
- Check wrapper.isBatch() before calling getData() and branch to getBatchData() when true.
- Trace where the wrapper was created — if it should be single, use wrap(AgentEndpoint) instead of wrap(Collection).
- If the consumer genuinely needs a single endpoint from a batch, call getBatchData() and pick the relevant entry explicitly.
Example fix
// before: assumes single, throws on batch wrapper
AgentEndpoint ep = wrapper.getData();
// after: check batch flag first
AgentEndpoint ep;
if (wrapper.isBatch()) {
Collection<AgentEndpoint> endpoints = wrapper.getBatchData();
ep = endpoints.iterator().next(); // or select by criteria
} else {
ep = wrapper.getData();
} Defensive patterns
Strategy: type-guard
Type guard
// Type guard: check isBatch before accessing single-item data
public AgentEndpoint safeGetSingle(AgentEndpointWrapper wrapper) {
if (wrapper.isBatch()) {
throw new IllegalStateException("Expected single endpoint, got batch");
}
return wrapper.getData();
} Try / catch
try {
AgentEndpoint ep = wrapper.getData();
} catch (UnsupportedOperationException e) {
// wrapper is in batch mode — use getBatchData() instead
log.warn("Wrapper is batch, falling back to getBatchData()");
Collection<AgentEndpoint> batch = wrapper.getBatchData();
} Prevention
- Always call isBatch() before getData() or getBatchData().
- Document the expected mode at the wrapper creation site.
- Use factory methods consistently: wrap(AgentEndpoint) for single, wrap(Collection) for batch.
When it happens
Trigger: Code calls wrapper.getData() on a wrapper instance that was created by AgentEndpointWrapper.wrap(Collection<AgentEndpoint>) — i.e., the wrapper holds a collection of endpoints but the caller expects a single endpoint. This typically happens when agent endpoint registration or redo logic processes batch registrations but a code path assumes a single endpoint.
Common situations: Agent endpoint redo/registration code path where batch registrations (AgentEndpointRegistrationBatch) are processed. A developer assumes a single-endpoint response but the wrapper was populated from a batch source. Refactoring that changed the wrap() call site from single to batch without updating the consumer.
Related errors
- Can't get batched data from single data.
- Agent Version storage {field} must be a string
- Agent Version storage {field} must be an integer
- NOT_MODIFIED
- 304
AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14).
Data as JSON: /api/errors/400ad562f0cce405.
Report an issue: GitHub.