apache/dubbo · error · IllegalArgumentException
value '%s' for key '%s' in '%s' is not a number
Error message
value '%s' for key '%s' in '%s' is not a number
What it means
Thrown by AbstractJsonUtilImpl.getNumberAsDouble(Map,String) when obj contains key but the value is neither a Double nor a String — i.e. it is a Long, Integer, Boolean, List, Map, or any other type the method does not handle. The method only accepts Double or parseable String; other numeric boxed types (Long/Integer) are NOT auto-promoted and fall through to this terminal IllegalArgumentException naming the value, key, and the whole object.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java:133
public Double getNumberAsDouble(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (value instanceof Double) {
return (Double) value;
}
if (value instanceof String) {
try {
return Double.parseDouble((String) value);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' is not a double", value, key));
}
}
throw new IllegalArgumentException(
String.format("value '%s' for key '%s' in '%s' is not a number", value, key, obj));
}
/**
* Gets a number from an object for the given key, casted to an integer. If the key is not
* present, this returns null. If the value does not represent an integer, throws an exception.
*/
@Override
public Integer getNumberAsInteger(Map<String, ?> obj, String key) {
assert obj != null;
assert key != null;
if (!obj.containsKey(key)) {
return null;
}
Object value = obj.get(key);
if (value instanceof Double) {
Double d = (Double) value;
int i = d.intValue();View on GitHub (pinned to 3a3043227f)
Solutions
- Normalize the value to Double before calling: handle Long/Integer/Number via ((Number) value).doubleValue().
- Use a different accessor that accepts any Number, or widen getNumberAsDouble's contract with a pre-check.
- Align the JSON deserializer so numeric fields decode to Double consistently.
- Catch IllegalArgumentException and report the offending key/type for triage.
Example fix
// before
Double v = jsonUtil.getNumberAsDouble(obj, "count"); // value is Long 5
// after - promote any Number
Object raw = obj.get("count");
Double v = raw instanceof Number ? ((Number) raw).doubleValue() : jsonUtil.getNumberAsDouble(obj, "count"); Defensive patterns
Strategy: type-guard
Validate before calling
Object raw = obj.get(key);
if (raw instanceof Number && !(raw instanceof Double)) {
return ((Number) raw).doubleValue(); // promote Long/Integer/etc.
}
return jsonUtil.getNumberAsDouble(obj, key); Type guard
private static boolean isDoubleOrString(Object value) {
return value instanceof Double || value instanceof String;
} Try / catch
try {
return jsonUtil.getNumberAsDouble(obj, key);
} catch (IllegalArgumentException e) {
Object raw = obj.get(key);
if (raw instanceof Number) return ((Number) raw).doubleValue(); // recover from Long/Integer
throw e;
} Prevention
- Promote any Number to Double before calling getNumberAsDouble, since it only accepts Double.
- Be aware this accessor does NOT auto-promote Long/Integer even though they are numeric.
- Align the JSON deserializer to emit Double for numeric fields read by this accessor.
When it happens
Trigger: jsonUtil.getNumberAsDouble(obj, key) where obj.get(key) is a Long, Integer, Float, BigDecimal, Boolean, List, or Map. Common case: JSON deserializers that produce Long/Integer for whole-number fields, or a field holding a nested object/array where a number was expected.
Common situations: Switching JSON backends that emit Long/Integer/BigInteger where the previous backend emitted Double; whole-number JSON values parsed into Long by a stricter parser; a field that is sometimes a number and sometimes a sub-object; misconfigured mapping that bound a number field to a generic Object.
Related errors
- value '%s' for key '%s' is not a double
- value '%s' for key '%s' is not an integer
- value '%s' for key '%s' is not a long integer
- value '%s' for key '%s' in '%s' is not List
- value '%s' for key '%s' in '%s' is not object
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/bd5243529302da20.
Report an issue: GitHub.