{"record":{"id":"bd5243529302da20","repo":"apache/dubbo","slug":"value-s-for-key-s-in-s-is-not-a-number","errorCode":null,"errorMessage":"value '%s' for key '%s' in '%s' is not a number","messagePattern":"value '(.+?)' for key '(.+?)' in '(.+?)' is not a number","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java","lineNumber":133,"sourceCode":"    public Double getNumberAsDouble(Map<String, ?> obj, String key) {\n        assert obj != null;\n        assert key != null;\n        if (!obj.containsKey(key)) {\n            return null;\n        }\n        Object value = obj.get(key);\n        if (value instanceof Double) {\n            return (Double) value;\n        }\n        if (value instanceof String) {\n            try {\n                return Double.parseDouble((String) value);\n            } catch (NumberFormatException e) {\n                throw new IllegalArgumentException(\n                        String.format(\"value '%s' for key '%s' is not a double\", value, key));\n            }\n        }\n        throw new IllegalArgumentException(\n                String.format(\"value '%s' for key '%s' in '%s' is not a number\", value, key, obj));\n    }\n\n    /**\n     * Gets a number from an object for the given key, casted to an integer.  If the key is not\n     * present, this returns null.  If the value does not represent an integer, throws an exception.\n     */\n    @Override\n    public Integer getNumberAsInteger(Map<String, ?> obj, String key) {\n        assert obj != null;\n        assert key != null;\n        if (!obj.containsKey(key)) {\n            return null;\n        }\n        Object value = obj.get(key);\n        if (value instanceof Double) {\n            Double d = (Double) value;\n            int i = d.intValue();","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java#L115-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nDouble v = jsonUtil.getNumberAsDouble(obj, \"count\"); // value is Long 5\n// after - promote any Number\nObject raw = obj.get(\"count\");\nDouble v = raw instanceof Number ? ((Number) raw).doubleValue() : jsonUtil.getNumberAsDouble(obj, \"count\");","handlingStrategy":"type-guard","validationCode":"Object raw = obj.get(key);\nif (raw instanceof Number && !(raw instanceof Double)) {\n    return ((Number) raw).doubleValue(); // promote Long/Integer/etc.\n}\nreturn jsonUtil.getNumberAsDouble(obj, key);","typeGuard":"private static boolean isDoubleOrString(Object value) {\n    return value instanceof Double || value instanceof String;\n}","tryCatchPattern":"try {\n    return jsonUtil.getNumberAsDouble(obj, key);\n} catch (IllegalArgumentException e) {\n    Object raw = obj.get(key);\n    if (raw instanceof Number) return ((Number) raw).doubleValue(); // recover from Long/Integer\n    throw e;\n}","preventionTips":["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."],"tags":["json","type-mismatch","number-parsing","argument","jsonutil","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}