{"record":{"id":"fb04339c451f73bf","repo":"elastic/elasticsearch","slug":"failed-to-parse-object","errorCode":null,"errorMessage":"[{}] failed to parse object","messagePattern":"\\[(.+?)\\] failed to parse object","errorType":"exception","errorClass":"XContentParseException","httpStatus":null,"severity":"error","filePath":"libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java","lineNumber":388,"sourceCode":"    private static void maybeMarkRequiredField(String currentFieldName, List<String[]> requiredFields) {\n        Iterator<String[]> iter = requiredFields.iterator();\n        while (iter.hasNext()) {\n            String[] requiredFieldNames = iter.next();\n            for (String field : requiredFieldNames) {\n                if (field.equals(currentFieldName)) {\n                    iter.remove();\n                    break;\n                }\n            }\n        }\n    }\n\n    @Override\n    public Value apply(XContentParser parser, Context context) {\n        try {\n            return parse(parser, context);\n        } catch (IOException e) {\n            throw new XContentParseException(parser.getTokenLocation(), \"[\" + name + \"] failed to parse object\", e);\n        }\n    }\n\n    public interface Parser<Value, Context> {\n        void parse(XContentParser parser, Value value, Context context) throws IOException;\n    }\n\n    public void declareField(Parser<Value, Context> p, ParseField parseField, ValueType type) {\n        if (parseField == null) {\n            throw new IllegalArgumentException(\"[parseField] is required\");\n        }\n        if (type == null) {\n            throw new IllegalArgumentException(\"[type] is required\");\n        }\n        FieldParser fieldParser = new FieldParser(p, type.supportedTokens(), parseField, type);\n        for (String fieldValue : parseField.getAllNamesIncludedDeprecated()) {\n\n            if (RestApiVersion.minimumSupported().matches(parseField.getForRestApiVersion())) {","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java#L370-L406","documentation":"Thrown by ObjectParser.apply() when the underlying parse() method throws an IOException. The apply method is a convenience entry point that wraps checked IOException into an unchecked XContentParseException so callers do not need to handle IOException directly. The original IOException is attached as the cause.","triggerScenarios":"Any low-level I/O failure during XContent parsing: a closed or disconnected input stream, truncated bytes that cause the parser to hit EOF mid-token, encoding issues where the byte stream is not valid UTF-8 (for JSON), or SMILE/CBOR binary format corruption.","commonSituations":"Network connection dropping mid-request causing truncated body. Reverse proxy timeout cutting off the request body. Double-reading the input stream so it is exhausted before ObjectParser runs. Encoding mismatch (e.g., sending gzip-compressed bytes without declaring Content-Encoding).","solutions":["Inspect the cause (IOException) in the exception for the specific I/O failure type.","Verify the request body is complete and not truncated by checking Content-Length matches actual body size.","Ensure the input source (stream, bytes) is not consumed or closed before parsing.","Check for encoding issues: valid UTF-8 for JSON, correct binary encoding for SMILE/CBOR."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before parsing, verify the input is readable and non-empty\nif (inputStream == null || (inputStream.available() == 0 && inputStream.markSupported())) {\n    throw new IllegalArgumentException(\"Input stream is empty or null\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return objectParser.apply(parser, context);\n} catch (XContentParseException e) {\n    if (e.getCause() instanceof IOException ioEx) {\n        logger.error(\"I/O failure during parsing: {}\", ioEx.getMessage());\n        return ResponseEntity.status(502).body(\"Upstream I/O error\");\n    }\n    throw e;\n}","preventionTips":["Ensure the request body stream is fully buffered before parsing.","Verify Content-Length matches the actual body size received.","Do not close or consume the input stream before the parser reads it.","Check for encoding issues: ensure the body is valid UTF-8 for JSON."],"tags":["parsing","xcontent","io-error","object-parser"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}