apache/dubbo · error · IllegalArgumentException
Arguments' types are different
Error message
Arguments' types are different
What it means
Thrown by ArrayMerger.merge() when the arrays passed in have different component types. ArrayMerger is the Merger<Object[]> used by Dubbo's group/merger feature to combine array results returned by multiple group providers into one array; all arrays must share the same component type to be concatenated.
Source
Thrown at dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/merger/ArrayMerger.java:52
int i = 0;
while (i < items.length && items[i] == null) {
i++;
}
if (i == items.length) {
return new Object[0];
}
Class<?> type = items[i].getClass().getComponentType();
int totalLen = 0;
for (; i < items.length; i++) {
if (items[i] == null) {
continue;
}
Class<?> itemType = items[i].getClass().getComponentType();
if (itemType != type) {
throw new IllegalArgumentException("Arguments' types are different");
}
totalLen += items[i].length;
}
if (totalLen == 0) {
return new Object[0];
}
Object result = Array.newInstance(type, totalLen);
int index = 0;
for (Object[] array : items) {
if (array != null) {
System.arraycopy(array, 0, result, index, array.length);
index += array.length;
}
}
return (Object[]) result;View on GitHub (pinned to 3a3043227f)
Solutions
- Ensure all provider groups return arrays of the same component type for the merged method.
- If heterogeneous results are expected, merge at the application layer instead of using ArrayMerger, or normalize results to a common supertype array.
- Validate return-type consistency across group implementations before enabling the merger.
Example fix
// before: providers return different array types -> ArrayMerger throws
// groupA returns String[], groupB returns Object[] -> mismatch
// after: all groups return the same component type
public interface Foo { String[] list(); } // every group returns String[] Defensive patterns
Strategy: validation
Validate before calling
// Before merging group array results, validate component types agree
Set<Class<?>> types = Arrays.stream(items)
.filter(Objects::nonNull)
.map(a -> a.getClass().getComponentType())
.collect(Collectors.toSet());
if (types.size() > 1) {
throw new IllegalArgumentException("Refusing to merge arrays of differing types: " + types);
}
return ArrayMerger.INSTANCE.merge(items); Type guard
// Guard: all non-null arrays share the same component type
static boolean sameComponentType(Object[]... items) {
Class<?> t = null;
for (Object[] a : items) {
if (a == null) continue;
Class<?> c = a.getClass().getComponentType();
if (t == null) t = c;
else if (c != t) return false;
}
return true;
} Try / catch
try {
return ArrayMerger.INSTANCE.merge(parts);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("types are different")) {
// normalize to a common array type or merge manually
return mergeAsObjectList(parts);
}
throw e;
} Prevention
- Ensure all group providers return arrays of the same component type for merged methods.
- Add a contract test verifying return-type homogeneity across groups.
- If results are heterogeneous, merge at the application layer instead of via ArrayMerger.
When it happens
Trigger: A service method declared with an array return type and @DubboReference(merger=...) / group merging enabled, where different provider groups return arrays of incompatible component types (e.g., one returns String[] and another Integer[]).
Common situations: Mixed provider implementations returning different array element types for the same interface method; a provider returning null arrays plus typed arrays in a way that resolves to differing component types; misuse of the merger feature on heterogeneous group results.
Related errors
- Failed to invoke service {entry.getKey()}: {e.getMessage()}
- Can not merge result because missing method [ {merger} ] in
- There is no merger to merge result.
- INTERNAL_ERROR
- Invalid configurator rule, please specify at least one param
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/e1f623f2feed62d9.
Report an issue: GitHub.