{"record":{"id":"0ad6a485ec5ebe28","repo":"hibernate/hibernate-orm","slug":"expected-json-array-end-but-none-found","errorCode":null,"errorMessage":"Expected JSON array end, but none found.","messagePattern":"Expected JSON array end, but none found\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JsonHelper.java","lineNumber":302,"sourceCode":"\t\t\t\t\tarrayList.add( adapter.fromNumericValue(jdbcJavaType, elementJdbcType ,reader, options)  );\n\t\t\t\t\tbreak;\n\t\t\t\tcase BOOLEAN_VALUE:\n\t\t\t\t\tarrayList.add( reader.getBooleanValue() ? Boolean.TRUE : Boolean.FALSE );\n\t\t\t\t\tbreak;\n\t\t\t\tcase VALUE:\n\t\t\t\t\tarrayList.add( adapter.fromValue(jdbcJavaType, elementJdbcType ,reader, options) );\n\t\t\t\t\tbreak;\n\t\t\t\tcase OBJECT_START:\n\t\t\t\t\tassert elementJdbcType instanceof JsonJdbcType;\n\t\t\t\t\tfinal EmbeddableMappingType embeddableMappingType = ((JsonJdbcType) elementJdbcType).getEmbeddableMappingType();\n\t\t\t\t\tarrayList.add( consumeJsonDocumentItems(reader, embeddableMappingType, true, options) );\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new UnsupportedOperationException( \"Unexpected JSON type \" + type );\n\t\t\t}\n\t\t}\n\n\t\tthrow new IllegalArgumentException( \"Expected JSON array end, but none found.\" );\n\t}\n\n\n\tprivate static class CustomArrayList extends AbstractCollection<Object> implements Collection<Object> {\n\t\tObject[] array = ArrayHelper.EMPTY_OBJECT_ARRAY;\n\t\tint size;\n\n\t\tpublic void ensureCapacity(int minCapacity) {\n\t\t\tint oldCapacity = array.length;\n\t\t\tif ( minCapacity > oldCapacity ) {\n\t\t\t\tint newCapacity = oldCapacity + ( oldCapacity >> 1 );\n\t\t\t\tnewCapacity = Math.max( Math.max( newCapacity, minCapacity ), 10 );\n\t\t\t\tarray = Arrays.copyOf( array, newCapacity );\n\t\t\t}\n\t\t}\n\n\t\tpublic Object[] getUnderlyingArray() {\n\t\t\treturn array;","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/jdbc/JsonHelper.java#L284-L320","documentation":"JsonHelper.deserializeArray loops until the reader's ARRAY_END; if the reader is exhausted while still inside the array, it falls out of the loop and throws IllegalArgumentException('Expected JSON array end, but none found.') - the stored JSON array is truncated/unterminated (missing ']').","triggerScenarios":"Reading a JSON collection attribute whose column value is a truncated array: column length limits that cut the document, failed partial writes, or manual row edits.","commonSituations":"VARCHAR columns silently truncating long arrays on insert; bulk migrations copying fixed-width substrings; writers interrupted mid-write without transactional protection.","solutions":["Repair the broken rows and identify the writer that truncated them.","Move the column to a native JSON type or a larger length so arrays are never cut.","Write JSON columns only through the Hibernate mapping in transactions."],"exampleFix":"-- before: truncated array in column ('[1,2,3' ...)\n-- load fails: Expected JSON array end, but none found.\n\n-- after: find and repair broken rows, widen the column\nALTER TABLE product ALTER COLUMN tags TYPE jsonb;\nUPDATE product SET tags = '[]'\nWHERE tags IS NOT NULL AND NOT (tags::text LIKE '[%]');","handlingStrategy":"validation","validationCode":"// Confirm the column value is a complete array before the load\nstatic void assertWellFormedArray(String json) {\n    try {\n        new org.json.JSONArray(json); // throws on truncated/unterminated arrays\n    } catch (Exception e) {\n        throw new IllegalArgumentException(\"Broken JSON array in column: \" + json, e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return session.find(Product.class, id);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Expected JSON array end\")) {\n        // truncated array in the column: repair the row, widen the column type/length\n    } else {\n        throw e;\n    }\n}","preventionTips":["Prefer native JSON or large TEXT columns for collection-valued JSON","Guard against silent truncation (check DB strict mode / column lengths)","Write JSON only inside transactions through the mapped entity"],"tags":["hibernate","json","malformed-data","truncation","collection-mapping"],"backgroundTag":"malformed-json-data","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}