{"record":{"id":"14766ad4fb00e18d","repo":"apache/dubbo","slug":"value-s-for-key-s-is-not-an-integer","errorCode":null,"errorMessage":"value '%s' for key '%s' is not an integer","messagePattern":"value '(.+?)' for key '(.+?)' is not an integer","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java","lineNumber":161,"sourceCode":"        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();\n            if (i != d) {\n                throw new ClassCastException(\"Number expected to be integer: \" + d);\n            }\n            return i;\n        }\n        if (value instanceof String) {\n            try {\n                return Integer.parseInt((String) value);\n            } catch (NumberFormatException e) {\n                throw new IllegalArgumentException(\n                        String.format(\"value '%s' for key '%s' is not an integer\", value, key));\n            }\n        }\n        throw new IllegalArgumentException(String.format(\"value '%s' for key '%s' is not an integer\", value, key));\n    }\n\n    /**\n     * Gets a number from an object for the given key, casted to an long.  If the key is not\n     * present, this returns null.  If the value does not represent a long integer, throws an\n     * exception.\n     */\n    @Override\n    public Long getNumberAsLong(Map<String, ?> obj, String key) {\n        assert obj != null;\n        assert key != null;\n        if (!obj.containsKey(key)) {\n            return null;\n        }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java#L143-L179","documentation":"Thrown by AbstractJsonUtilImpl.getNumberAsInteger(Map,String) when obj contains key, the value is a String, but Integer.parseInt throws NumberFormatException. This is the string-parse failure path for the integer accessor; the IllegalArgumentException names the value and key. A true Double value is handled separately (error 191 for fractional, success for whole), and non-Double/non-String values hit error 193.","triggerScenarios":"jsonUtil.getNumberAsInteger(obj, key) where obj.get(key) is a String not parseable as a base-10 int — e.g. \"3.5\", \"abc\", \"\", \"1_000\", \"0x10\", a value with a decimal point, or out-of-int-range digits like \"99999999999\".","commonSituations":"Numeric field supplied as a decimal string (\"3.0\") where an int was expected; thousands separators/underscores; hex/scientific notation; a value larger than Integer.MAX_VALUE; free-text where a number was expected; locale formatting.","solutions":["If the value may be a decimal string, parse as Double then cast/round: (int) Double.parseDouble(s).","Sanitize the string (strip separators, trim) before relying on it.","If the value may exceed int range, use getNumberAsLong instead.","Align the producer to emit plain integer strings or JSON numbers."],"exampleFix":"// before\nInteger n = jsonUtil.getNumberAsInteger(obj, \"code\"); // \"3.0\"\n// after - tolerate decimal strings\nObject raw = obj.get(\"code\");\nInteger n = raw instanceof String ? (int) Double.parseDouble((String) raw) : jsonUtil.getNumberAsInteger(obj, \"code\");","handlingStrategy":"validation","validationCode":"Object raw = obj.get(key);\nif (raw instanceof String) {\n    String s = (String) raw;\n    try {\n        Integer.parseInt(s); // pre-check\n    } catch (NumberFormatException e) {\n        // try as decimal then cast\n        try { return (int) Double.parseDouble(s); }\n        catch (NumberFormatException ignored) { return null; }\n    }\n}\nreturn jsonUtil.getNumberAsInteger(obj, key);","typeGuard":"private static boolean isParsableInt(Object value) {\n    if (value instanceof Double) return value.equals(Math.rint((Double) value));\n    if (value instanceof String) {\n        try { Integer.parseInt((String) value); return true; }\n        catch (NumberFormatException e) { return false; }\n    }\n    return false;\n}","tryCatchPattern":"try {\n    return jsonUtil.getNumberAsInteger(obj, key);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"is not an integer\")) {\n        Object raw = obj.get(key);\n        if (raw instanceof String) return (int) Double.parseDouble((String) raw);\n    }\n    throw e;\n}","preventionTips":["Strip thousands separators and trim before parsing integer strings.","If the value may be a decimal string, parse as Double then cast to int.","For values that may exceed int range, use getNumberAsLong instead."],"tags":["json","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"}