alibaba/nacos · error · UnsupportedOperationException
Can't get batched data from single data.
Error message
Can't get batched data from single data.
What it means
Thrown as UnsupportedOperationException by AgentEndpointWrapper.getBatchData() when the wrapper was created in single mode (via wrap(AgentEndpoint)). getBatchData() is the batch accessor and is only valid on wrappers created via wrap(Collection<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:64
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();
}
private static Collection<AgentEndpoint> copyEndpoints(Collection<AgentEndpoint> source) {
List<AgentEndpoint> result = new ArrayList<AgentEndpoint>(source.size());
for (AgentEndpoint endpoint : source) {
result.add(copyEndpoint(endpoint));
}View on GitHub (pinned to 9b989acdf1)
Solutions
- Check wrapper.isBatch() before calling getBatchData() and branch to getData() when false.
- If the consumer needs batch semantics, ensure the wrapper is created via wrap(Collection) at the source.
- For generic code, normalize: if !isBatch(), wrap getData() result in Collections.singletonList() before processing as a collection.
Example fix
// before: always calls getBatchData, throws on single wrapper
Collection<AgentEndpoint> endpoints = wrapper.getBatchData();
// after: normalize to collection regardless of mode
Collection<AgentEndpoint> endpoints = wrapper.isBatch()
? wrapper.getBatchData()
: Collections.singletonList(wrapper.getData()); Defensive patterns
Strategy: type-guard
Type guard
// Type guard: normalize to collection regardless of wrapper mode
public Collection<AgentEndpoint> safeGetAll(AgentEndpointWrapper wrapper) {
if (wrapper.isBatch()) {
return wrapper.getBatchData();
}
return Collections.singletonList(wrapper.getData());
} Try / catch
try {
Collection<AgentEndpoint> endpoints = wrapper.getBatchData();
} catch (UnsupportedOperationException e) {
// wrapper is single mode — use getData() instead
AgentEndpoint single = wrapper.getData();
endpoints = Collections.singletonList(single);
} Prevention
- Use a normalization helper that checks isBatch() and returns a collection in both cases.
- Keep wrap() call sites and consumer code in sync — if you change one, update the other.
- Add unit tests covering both single and batch wrapper modes.
When it happens
Trigger: Code calls wrapper.getBatchData() on a wrapper instance created by AgentEndpointWrapper.wrap(AgentEndpoint) — i.e., the wrapper holds a single endpoint but the caller expects a collection. This happens when redo/registration logic processes a single endpoint but a code path assumes batch semantics.
Common situations: Agent endpoint registration where single and batch code paths share a consumer. A developer refactored to use batch access but the wrapper was still created in single mode. Generic processing code that always calls getBatchData() without checking isBatch().
Related errors
- Can't get single data from batched 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/a80c260b737ed71a.
Report an issue: GitHub.