{"record":{"id":"66a6abeb20f55ec0","repo":"elastic/elasticsearch","slug":"wrapped-ioexception-66a6ab","errorCode":null,"errorMessage":"<wrapped IOException>","messagePattern":"<wrapped IOException>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/JsonProcessor.java","lineNumber":140,"sourceCode":"                /*\n                 * If strict JSON parsing is disabled, then once we've found the first token then we move on. For example for the string\n                 * \"123 \\\"foo\\\"\" we would just return the first token, 123. However, if strict parsing is enabled (which it is by default),\n                 * then we check to see whether there are any more tokens at this point. We expect the next token to be null. If there is\n                 * another token or if the parser blows up, then we know we had invalid JSON and we alert the user with an\n                 * IllegalArgumentException.\n                 */\n                try {\n                    token = parser.nextToken();\n                } catch (IllegalArgumentException e) {\n                    throw new IllegalArgumentException(errorMessage, e);\n                }\n                if (token != null) {\n                    throw new IllegalArgumentException(errorMessage);\n                }\n            }\n            return value;\n        } catch (IOException e) {\n            throw new IllegalArgumentException(e);\n        }\n    }\n\n    public static void apply(\n        Map<String, Object> ctx,\n        String fieldName,\n        boolean allowDuplicateKeys,\n        ConflictStrategy conflictStrategy,\n        boolean strictJsonParsing\n    ) {\n        Object value = apply(ctx.get(fieldName), allowDuplicateKeys, strictJsonParsing);\n        mergeParsedJson(ctx, value, conflictStrategy);\n    }\n\n    private static void mergeParsedJson(Map<String, Object> ctx, Object value, ConflictStrategy conflictStrategy) {\n        if (value instanceof Map) {\n            @SuppressWarnings(\"unchecked\")\n            Map<String, Object> map = (Map<String, Object>) value;","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/JsonProcessor.java#L122-L158","documentation":"JsonProcessor.apply wraps any IOException from the XContentParser in an IllegalArgumentException with the placeholder message. Since the parser reads from an in-memory string, an IOException indicates a parser-level fault rather than a real I/O issue. The original IOException is the cause of the thrown IllegalArgumentException.","triggerScenarios":"The JSON parser threw an IOException parsing the fieldValue string — typically malformed JSON that fails during tokenization rather than grammar validation.","commonSituations":"Truncated or corrupted JSON in the field, encoding issues (non-UTF8 bytes decoded wrongly), or parser bugs.","solutions":["Inspect the wrapped IOException cause in server logs for the specific parser failure.","Validate the input field is well-formed JSON before invoking the json processor.","If the data is legitimately non-JSON, route it differently or pre-clean it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate JSON well-formedness with the same parser\ntry (XContentParser p = JsonXContent.jsonXContent.createParser(\n        XContentParserConfiguration.EMPTY, value)) {\n    while (p.nextToken() != null) {}\n} catch (IOException ioe) {\n    // value is not parseable — handle before invoking processor\n}","typeGuard":null,"tryCatchPattern":"try {\n    JsonProcessor.apply(value, allowDup, strict);\n} catch (IllegalArgumentException e) {\n    if (e.getCause() instanceof IOException) {\n        // log cause and route to failure store\n    } else throw e;\n}","preventionTips":["Inspect server logs for the wrapped IOException cause to find the real fault.","Validate JSON well-formedness upstream with a script processor.","Watch for encoding issues (non-UTF-8 bytes) in source data."],"tags":["ingest","json","ioexception","parser"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}