{"record":{"id":"7a3607e3351cecca","repo":"stanfordnlp/CoreNLP","slug":"last-character-of-encoded-pair-is-escape-character","errorCode":null,"errorMessage":"Last character of encoded pair is escape character: \" + encoded","messagePattern":"Last character of encoded pair is escape character: \" \\+ encoded","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/StringUtils.java","lineNumber":2648,"sourceCode":"    if(chars[0] == '('){ start += 1; end -= 1; if(chars[end] != ')') throw new IllegalArgumentException(\"Unclosed paren in encoded map: \" + encoded); }\n    if(chars[0] == '['){ start += 1; end -= 1; if(chars[end] != ']') throw new IllegalArgumentException(\"Unclosed bracket in encoded map: \" + encoded); }\n    if(chars[0] == '{'){ start += 1; end -= 1; if(chars[end] != '}') throw new IllegalArgumentException(\"Unclosed bracket in encoded map: \" + encoded); }\n    //(finite state automata)\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) {\n          throw new IllegalArgumentException(\"Last character of encoded pair is escape character: \" + encoded);\n        }\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] == '\\n' && current.length() == 0) {\n          // current.append(\"\");  // do nothing\n        } else if(chars[i] == ',' || chars[i] == ';' || chars[i] == '\\t' || chars[i] == '\\n'){\n          // case: end a value\n          if (onKey) {\n            throw new IllegalArgumentException(\"Encountered key without value\");\n          }\n          if (current.length() > 0) {\n            value = current.toString().trim();","sourceCodeStart":2630,"sourceCodeEnd":2666,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/StringUtils.java#L2630-L2666","documentation":"During the encoded-map scan, a backslash denotes an escaped character and consumes the next character literally. A backslash as the final character of the input has nothing to escape, so the map string is malformed and the decoder throws this IllegalArgumentException (message says 'pair').","triggerScenarios":"Passing an encoded map whose very last character is a lone backslash, e.g. \"{a->b\\\\}\" written in Java so the raw text ends with '\\\\'; an encoder bug dropping the escaped character.","commonSituations":"Backslash escaping mistakes in Java literals; file/serialization truncation right after a backslash; Windows path values inserted without escaping.","solutions":["Escape the backslash itself ('\\\\\\\\') or remove the trailing one","Fix the encoder to never end output with a lone backslash","Check double-escaping when embedding the string in Java source","Validate the string does not end with '\\\\' before decoding"],"exampleFix":"// before\nString m = \"{a->C:\\\\path\\\\}\"; // raw text ends with backslash\n// after\nString m = \"{a->C:\\\\\\\\path\\\\\\\\}\"; // escapes decodable to C:\\path\\","handlingStrategy":"validation","validationCode":"if (s != null && s.endsWith(\"\\\\\")) throw new IllegalArgumentException(\"Encoded map must not end with a lone backslash\");","typeGuard":"static boolean mapEndsWithEscape(String s) { return s != null && !s.isEmpty() && s.charAt(s.length()-1) == '\\\\'; }","tryCatchPattern":"try { map = StringUtils.decodeMap(encoded); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"escape character\")) { /* fix escaping and retry once */ } else throw e; }","preventionTips":["Double backslashes in Java literals and Windows paths","Fix encoders to never emit a dangling escape","Strip or escape trailing backslashes before decoding"],"tags":["java","string-parsing","escape-character","map-parsing"],"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"}