{"record":{"id":"2a8d968ef5c7e265","repo":"stanfordnlp/CoreNLP","slug":"last-character-of-encoded-array-is-escape-characte","errorCode":null,"errorMessage":"Last character of encoded array is escape character: \" + encoded","messagePattern":"Last character of encoded array is escape character: \" \\+ encoded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2582,"sourceCode":"    int start = 0; int end = chars.length;\n    if(chars[0] == '('){ start += 1; end -= 1; if(chars[end] != ')') throw new IllegalArgumentException(\"Unclosed paren in encoded array: \" + encoded); }\n    if(chars[0] == '['){ start += 1; end -= 1; if(chars[end] != ']') throw new IllegalArgumentException(\"Unclosed bracket in encoded array: \" + encoded); }\n    if(chars[0] == '{'){ start += 1; end -= 1; if(chars[end] != '}') throw new IllegalArgumentException(\"Unclosed bracke in encoded array: \" + encoded); }\n    // (finite state automaton)\n    for (int i=start; i<end; i++) {\n      if (chars[i] == '\\r') {\n        // Ignore funny windows carriage return\n        continue;\n      } else if (quoteCloseChar != 0) {\n        //(case: in quotes)\n        if(chars[i] == quoteCloseChar){\n          quoteCloseChar = (char) 0;\n        }else{\n          current.append(chars[i]);\n        }\n      } else if(chars[i] == '\\\\'){\n        //(case: escaped character)\n        if(i == chars.length - 1) throw new IllegalArgumentException(\"Last character of encoded array is escape character: \" + encoded);\n        current.append(chars[i+1]);\n        i += 1;\n      } else {\n        //(case: normal)\n        if (chars[i] == '\"') {\n          quoteCloseChar = '\"';\n        } else if(chars[i] == '\\'') {\n          quoteCloseChar = '\\'';\n        } else if(chars[i] == ',' || chars[i] == ';' || chars[i] == ' ' || chars[i] == '\\t' || chars[i] == '\\n') {\n          //break\n          if (current.length() > 0) {\n            terms.add(current.toString().trim());\n          }\n          current = new StringBuilder();\n        } else {\n          current.append(chars[i]);\n        }\n      }","sourceCodeStart":2564,"sourceCodeEnd":2600,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2564-L2600","documentation":"During the finite-state scan of an encoded array, a backslash starts an escape sequence: the next character is taken literally. If the backslash is the very last character of the input there is nothing to escape, so the input is malformed and the decoder throws this IllegalArgumentException.","triggerScenarios":"Passing an encoded array whose final character is a lone backslash, e.g. \"(a,b\\\\)\" in Java source where the raw string ends in '\\\\'; trailing escape produced by an escaping bug in the encoder.","commonSituations":"Double-escaping mistakes in Java string literals (miscounting backslashes); encoders that escape but drop the escaped char; truncation cutting the string right after a backslash.","solutions":["Remove the trailing backslash or supply the character it should escape","Fix the encoder so escapes are always followed by the escaped character","Check for double-escaping in Java string literals (\"\\\\\\\\\" vs \"\\\\\")","Validate the string ends with a legal (non-escape) character before decoding"],"exampleFix":"// before\nString encoded = \"(a,b\\\\)\"; // raw string ends with backslash\n// after\nString encoded = \"(a,b\\\\\\\\)\"; // escaped backslash, decodes to (a,b\\)","handlingStrategy":"validation","validationCode":"if (s != null && s.endsWith(\"\\\\\")) throw new IllegalArgumentException(\"Encoded string must not end with a lone backslash\");","typeGuard":"static boolean endsWithLoneEscape(String s) { return s != null && !s.isEmpty() && s.charAt(s.length()-1) == '\\\\'; }","tryCatchPattern":"try { terms = StringUtils.decode(encoded); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"escape character\")) { /* repair or reject input */ } else throw e; }","preventionTips":["Escape backslashes as '\\\\\\\\' in Java literals","Have encoders guarantee no output ends with a lone backslash","Check for double-escaping when strings pass through multiple layers"],"tags":["java","string-parsing","escape-character","illegal-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}