{"record":{"id":"dda8f21bbeaaedbe","repo":"stanfordnlp/CoreNLP","slug":"invalid-format","errorCode":null,"errorMessage":"invalid format: ||","messagePattern":"invalid format: \\|\\|","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/stats/ClassicCounter.java","lineNumber":590,"sourceCode":"        result.setCount(fields[0], Double.parseDouble(fields[1]));\n      }\n      return result;\n    }\n\n\n  /**\n   * Converts from the format printed by the toString method back into\n   * a Counter&lt;String&gt;.  The toString() doesn't escape, so this only\n   * works providing the keys of the Counter do not have commas or equals signs\n   * in them.\n   *\n   * @param s A String representation of a Counter\n   * @return The Counter\n   */\n  public static ClassicCounter<String> fromString(String s) {\n    ClassicCounter<String> result = new ClassicCounter<>();\n    if (!s.startsWith(\"{\") || !s.endsWith(\"}\")) {\n      throw new RuntimeException(\"invalid format: ||\"+s+\"||\");\n    }\n    s = s.substring(1, s.length()-1);\n    String[] lines = s.split(\", \");\n    for (String line : lines) {\n      String[] fields = line.split(\"=\");\n      if (fields.length!=2) throw new RuntimeException(\"Got unsplittable line: \\\"\" + line + '\\\"');\n      result.setCount(fields[0], Double.parseDouble(fields[1]));\n    }\n    return result;\n  }\n\n  /**\n   * {@inheritDoc}\n   */\n  @Override\n  public void prettyLog(RedwoodChannels channels, String description) {\n    PrettyLogger.log(channels, description, Counters.asMap(this));\n  }","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/stats/ClassicCounter.java#L572-L608","documentation":"ClassicCounter.fromString expects the string produced by ClassicCounter.toString(): it must start with '{' and end with '}'. Otherwise it throws RuntimeException(\"invalid format: ||s||\"). The || markers are just delimiters around the offending string in the message.","triggerScenarios":"Calling ClassicCounter.fromString with a string that is not the toString() form of a counter — e.g. missing braces, empty string, whitespace-wrapped output, or a serialized file with corrupted first/last characters.","commonSituations":"Persisting a counter to a file and reading it back with encoding/BOM issues; concatenating counters incorrectly; passing JSON or TSV text to fromString by mistake.","solutions":["Ensure input is the exact toString() output of a ClassicCounter (with braces)","Trim the string and strip a possible BOM before calling fromString","If the data is TSV key/value pairs, use valueOfIgnoreComments instead of fromString"],"exampleFix":"// before\nClassicCounter<String> c = ClassicCounter.fromString(fileLine.trim() + \";\");\n// after\nString s = fileLine.replace(\"\\uFEFF\", \"\").trim();\nif (!s.startsWith(\"{\") || !s.endsWith(\"}\")) {\n  throw new IllegalArgumentException(\"counter string must be {k=v, ...} form\");\n}\nClassicCounter<String> c = ClassicCounter.fromString(s);","handlingStrategy":"validation","validationCode":"boolean isCounterString(String s) {\n  String t = s == null ? \"\" : s.replace(\"\\uFEFF\", \"\").trim();\n  return t.startsWith(\"{\") && t.endsWith(\"}\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  c = ClassicCounter.fromString(s);\n} catch (RuntimeException e) {\n  throw new IllegalArgumentException(\"expected toString() form {k=v, ...}\", e);\n}","preventionTips":["Round-trip only via toString()/fromString()","Strip BOM and surrounding whitespace before parsing","Use TSV loaders for hand-authored data instead of fromString"],"tags":["java","parsing","serialization","format"],"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-15T23:17:13.987Z"}