{"record":{"id":"3df20379b01ef37d","repo":"hibernate/hibernate-orm","slug":"cannot-parse-given-string-into-array-of-strings-o","errorCode":null,"errorMessage":"Cannot parse given string into array of strings. Outside of quote, but neither whitespace, comma, array end, nor null found.","messagePattern":"Cannot parse given string into array of strings\\. Outside of quote, but neither whitespace, comma, array end, nor null found\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java","lineNumber":238,"sourceCode":"\t\t\t\t\t\tsb = null;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\t// i + 4, because there has to be a comma or closing brace after null\n\t\t\t\t\tif ( i + 4 < len\n\t\t\t\t\t\t\t&& charSequence.charAt( i ) == 'n'\n\t\t\t\t\t\t\t&& charSequence.charAt( i + 1 ) == 'u'\n\t\t\t\t\t\t\t&& charSequence.charAt( i + 2 ) == 'l'\n\t\t\t\t\t\t\t&& charSequence.charAt( i + 3 ) == 'l') {\n\t\t\t\t\t\tlst.add( null );\n\t\t\t\t\t\ti += 4;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (i + 1 == len) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tthrow new IllegalArgumentException( \"Cannot parse given string into array of strings.\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t+ \" Outside of quote, but neither whitespace, comma, array end, nor null found.\" );\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if ( c == '\\\\' && i + 2 < len && (charSequence.charAt( i + 1 ) == '\\\\' || charSequence.charAt( i + 1 ) == '\"')) {\n\t\t\t\tc = charSequence.charAt( ++i );\n\t\t\t}\n\t\t\t// If there is ever a null-pointer here, the if-else logic before is incomplete\n\t\t\tsb.append( c );\n\t\t}\n\t\t//noinspection unchecked\n\t\tfinal var result = (T[]) newInstance( getElementJavaType().getJavaTypeClass(), lst.size() );\n\t\tfor ( int i = 0; i < result.length; i ++ ) {\n\t\t\tif ( lst.get( i ) != null ) {\n\t\t\t\tresult[i] = getElementJavaType().fromString( lst.get( i ) );\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/ArrayJavaType.java#L220-L256","documentation":"The in-loop companion of ArrayJavaType.fromString: while scanning the '{...}' literal it hit a character outside quotes that is neither whitespace, a comma, the closing '}' nor the start of the token 'null'. The literal is syntactically malformed at that position.","triggerScenarios":"An array literal containing unquoted special characters, e.g. '{a{b}', '{x y z;w}', stray text after an element ('{a b}' is fine as separator-free whitespace but '{a;b}' is not), or a truncated value like '{a,b' where the parser walks past garbage before reaching the missing '}'.","commonSituations":"Elements containing commas, semicolons, braces or backslashes stored without quoting; hand-built literal strings via naive string concatenation; escaped-quote handling that dropped the closing quote ('{\"a}' leaves the parser mid-token); data corruption/truncation in the varchar column backing the array.","solutions":["Quote any element containing ',', ';', '{', '}' or '\"' and escape embedded quotes/backslashes (\"\\\"\" and \"\\\\\")","Build literals with a proper formatter or let the driver/ORM write them instead of string concatenation","Repair truncated/corrupt rows (validate with a regex like ^\\{.*\\}$ plus per-token checks)","Add a converter that normalizes the stored text before Hibernate parses it"],"exampleFix":"// before\nString literal = \"{amount;total}\";          // ';' illegal outside quotes -> IllegalArgumentException\n// after\nString literal = \"{\\\"amount;total\\\"}\";        // quoted element: {\"amount;total\"}","handlingStrategy":"validation","validationCode":"// per-element formatter that quotes/escapes everything risky\nstatic String pgArrayLiteral(List<String> elems) {\n    return elems.stream()\n        .map(e -> e == null ? \"null\" : '\"' + e.replace(\"\\\\\", \"\\\\\\\\\").replace(\"\\\"\", \"\\\\\\\"\") + '\"')\n        .collect(joining(\",\", \"{\", \"}\"));\n}","typeGuard":"static boolean onlyLegalTokens(CharSequence s) {\n    boolean inQuote = false;\n    for (int i = 1; i < s.length() - 1; i++) {\n        char c = s.charAt(i);\n        if (c == '\"') inQuote = !inQuote;\n        else if (!inQuote && !Character.isWhitespace(c) && c != ',' && c != 'n' && c != 'u' && c != 'l') return false;\n    }\n    return !inQuote;\n}","tryCatchPattern":"try {\n    doc.setTags(literal);\n    session.flush();\n} catch (IllegalArgumentException e) {\n    if (String.valueOf(e.getMessage()).contains(\"Outside of quote\")) {\n        doc.setTags(pgArrayLiteral(tagList)); // rewrite in canonical literal form and retry\n        session.flush();\n    } else throw e;\n}","preventionTips":["Always build literals with a quoting formatter, never concatenation","Escape backslash and double-quote inside quoted elements","Fuzz-test any hand-rolled literal builder with special characters","Prefer native array columns over varchar hacks"],"tags":["hibernate","orm","array-mapping","parsing","postgresql","data-format"],"backgroundTag":"array-literal-parse-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}