{"record":{"id":"3fa2166cbcb55c27","repo":"alibaba/nacos","slug":"must-be-a-finite-json-number","errorCode":null,"errorMessage":"{} must be a finite JSON number","messagePattern":"(.+?) must be a finite JSON number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/metadata/AgentResourceExtSerializer.java","lineNumber":179,"sourceCode":"            bytes = JacksonUtils.toJsonBytes(extensions);\n        } catch (NacosSerializationException e) {\n            throw new IllegalArgumentException(\"Unable to serialize Agent extensions\", e);\n        }\n        if (bytes.length > MAX_EXTENSIONS_SIZE) {\n            throw new IllegalArgumentException(\n                \"Agent extensions exceeds \" + MAX_EXTENSIONS_SIZE + \" bytes\");\n        }\n    }\n    \n    private static void validateJsonValue(Object value, String fieldName) {\n        if (value == null || value instanceof String || value instanceof Boolean\n            || value instanceof Byte || value instanceof Short || value instanceof Integer\n            || value instanceof Long) {\n            return;\n        }\n        if (value instanceof Float) {\n            if (!Float.isFinite((Float) value)) {\n                throw new IllegalArgumentException(fieldName + \" must be a finite JSON number\");\n            }\n            return;\n        }\n        if (value instanceof Double) {\n            if (!Double.isFinite((Double) value)) {\n                throw new IllegalArgumentException(fieldName + \" must be a finite JSON number\");\n            }\n            return;\n        }\n        if (value instanceof Number) {\n            return;\n        }\n        if (value instanceof List) {\n            for (Object item : (List<?>) value) {\n                validateJsonValue(item, fieldName);\n            }\n            return;\n        }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/metadata/AgentResourceExtSerializer.java#L161-L197","documentation":"validateJsonValue() rejects a Float extension value that is NaN or ±Infinity (Float.isFinite is false), because those have no valid JSON representation. Only finite floats are allowed.","triggerScenarios":"An extensions value is a Float computed from a division by zero, Math operations yielding infinity, or Float.parseFloat(\"NaN\"), then passed into the ext and serialized.","commonSituations":"Metrics/statistics code writing ratio or score floats into extensions without guarding against infinity; deserialization of a numeric token into Float that overflows.","solutions":["Sanitize float values before inserting into extensions: replace non-finite with null or a sentinel and skip, or use Double and clamp.","Use Float.isFinite(v) guard and drop/normalize the value if false.","Store precision-sensitive numbers as strings if you need exact representation."],"exampleFix":"// before\next.put(\"ratio\", numerator / (float) denominator); // denominator 0 -> Infinity\n\n// after\nfloat r = numerator / (float) denominator;\next.put(\"ratio\", Float.isFinite(r) ? r : null);","handlingStrategy":"validation","validationCode":"static Object sanitizeNumber(Object v) {\n    return (v instanceof Float && !Float.isFinite((Float) v)) ? null : v;\n}\n// apply before inserting into extensions","typeGuard":"static boolean isFiniteJsonNumber(Object v) {\n    if (v instanceof Float) return Float.isFinite((Float) v);\n    if (v instanceof Double) return Double.isFinite((Double) v);\n    return v instanceof Byte || v instanceof Short || v instanceof Integer || v instanceof Long || v instanceof Number;\n}","tryCatchPattern":null,"preventionTips":["Guard float results with Float.isFinite before insertion.","Treat division/log inputs defensively against zero/negative.","Store precision-sensitive values as strings if needed."],"tags":["ai-registry","agent","extensions","numeric"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}