stanfordnlp/CoreNLP · error · IllegalArgumentException

Last character of encoded pair is escape character: " +…

Error message

Last character of encoded pair is escape character: " + encoded

What it means

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').

Solutions

  1. Escape the backslash itself ('\\\\') or remove the trailing one
  2. Fix the encoder to never end output with a lone backslash
  3. Check double-escaping when embedding the string in Java source
  4. Validate the string does not end with '\\' before decoding

Example fix

// before
String m = "{a->C:\\path\\}"; // raw text ends with backslash
// after
String m = "{a->C:\\\\path\\\\}"; // escapes decodable to C:\path\
Defensive patterns

Strategy: validation

Validate before calling

if (s != null && s.endsWith("\\")) throw new IllegalArgumentException("Encoded map must not end with a lone backslash");

Type guard

static boolean mapEndsWithEscape(String s) { return s != null && !s.isEmpty() && s.charAt(s.length()-1) == '\\'; }

Try / catch

try { map = StringUtils.decodeMap(encoded); } catch (IllegalArgumentException e) { if (e.getMessage().contains("escape character")) { /* fix escaping and retry once */ } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: Backslash escaping mistakes in Java literals; file/serialization truncation right after a backslash; Windows path values inserted without escaping.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/7a3607e3351cecca. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/StringUtils.java:2648

    if(chars[0] == '('){ start += 1; end -= 1; if(chars[end] != ')') throw new IllegalArgumentException("Unclosed paren in encoded map: " + encoded); }
    if(chars[0] == '['){ start += 1; end -= 1; if(chars[end] != ']') throw new IllegalArgumentException("Unclosed bracket in encoded map: " + encoded); }
    if(chars[0] == '{'){ start += 1; end -= 1; if(chars[end] != '}') throw new IllegalArgumentException("Unclosed bracket in encoded map: " + encoded); }
    //(finite state automata)
    for(int i=start; i<end; i++){
      if (chars[i] == '\r') {
        // Ignore funny windows carriage return
        continue;
      } else if(quoteCloseChar != 0){
        //(case: in quotes)
        if(chars[i] == quoteCloseChar){
          quoteCloseChar = (char) 0;
        }else{
          current.append(chars[i]);
        }
      } else if(chars[i] == '\\'){
        //(case: escaped character)
        if(i == chars.length - 1) {
          throw new IllegalArgumentException("Last character of encoded pair is escape character: " + encoded);
        }
        current.append(chars[i+1]);
        i += 1;
      }else{
        //(case: normal)
        if (chars[i] == '"') {
          quoteCloseChar = '"';
        } else if(chars[i] == '\'') {
          quoteCloseChar = '\'';
        } else if (chars[i] == '\n' && current.length() == 0) {
          // current.append("");  // do nothing
        } else if(chars[i] == ',' || chars[i] == ';' || chars[i] == '\t' || chars[i] == '\n'){
          // case: end a value
          if (onKey) {
            throw new IllegalArgumentException("Encountered key without value");
          }
          if (current.length() > 0) {
            value = current.toString().trim();

View on GitHub (pinned to 1b7edd19c4)