{"record":{"id":"cd32c7e1f2cbc606","repo":"stanfordnlp/CoreNLP","slug":"bad-line","errorCode":null,"errorMessage":"Bad line: ","messagePattern":"Bad line: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sequences/MalletReaderAndWriter.java","lineNumber":67,"sourceCode":"  int num = 0;\n  private class MalletDocParser implements Serializable, Function<String,List<CoreLabel>> {\n    private static final long serialVersionUID = -6211332661459630572L;\n    @Override\n    public List<CoreLabel> apply(String doc) {\n\n      if (num % 1000 == 0) { log.info(\"[\"+num+\"]\"); }\n      num++;\n      \n      List<CoreLabel> words = new ArrayList<>();\n      \n      String[] lines = doc.split(\"\\n\");\n\n      for (String line : lines) {\n        if (line.trim().length() < 1)\n          continue;\n        int idx = line.lastIndexOf(\" \");\n        if (idx < 0)\n          throw new RuntimeException(\"Bad line: \" + line);\n        CoreLabel wi = new CoreLabel();\n        wi.setWord(line.substring(0, idx));\n        wi.set(CoreAnnotations.AnswerAnnotation.class, line.substring(idx + 1));\n        wi.set(CoreAnnotations.GoldAnswerAnnotation.class, line.substring(idx + 1));\n        words.add(wi);\n      }\n      return words;\n    }\n  }\n  \n  @Override\n  public void printAnswers(List<CoreLabel> doc, PrintWriter out) {\n    for (CoreLabel wi : doc) {\n      String answer = wi.get(CoreAnnotations.AnswerAnnotation.class);\n      String goldAnswer = wi.get(CoreAnnotations.GoldAnswerAnnotation.class);\n      out.println(wi.word() + \"\\t\" + goldAnswer + \"\\t\" + answer);\n    }\n    out.println();","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sequences/MalletReaderAndWriter.java#L49-L85","documentation":"MalletReaderAndWriter reads CRF training/test data in Mallet's 'word TAB label' format. For each non-blank line it takes the last space as the word/label separator; if a line contains no space at all it cannot be split into a token and a label, so it throws this RuntimeException. It is a data-format error in the input file, not a library bug.","triggerScenarios":"Calling MalletReaderAndWriter.apply() (via a ColumnDocumentReaderAndWriter-style pipeline) with an input line that has no space character, e.g. a single-token line like 'Hello' instead of 'Hello O', or a line separated by tabs instead of spaces.","commonSituations":"Converting Mallet or custom corpora to Stanford NLP CRF format; lines with only a word and no gold label; trailing junk lines in a .txt training file; using TAB separators after a script changed the delimiter.","solutions":["Fix the offending input line so it contains 'word label' separated by a space (the LAST space splits word from label).","Remove or blank out empty/junk lines that contain non-whitespace characters but no space.","Verify the reader matches your file's delimiter; if your file is tab-separated, pre-convert tabs to spaces or use a reader configured for your format.","Wrap the read loop and log the failing line to locate it, then correct it in the source corpus."],"exampleFix":"// before (bad input line)\nHello\n// after\nHello O","handlingStrategy":"validation","validationCode":"for (String line : lines) {\n  if (line.trim().isEmpty()) continue;\n  if (line.lastIndexOf(\" \") < 0) {\n    throw new IllegalArgumentException(\"Input line has no 'word label' separator: \" + line);\n  }\n}","typeGuard":"boolean isMalletLine(String line) { return line != null && line.trim().length() > 0 && line.lastIndexOf(\" \") >= 0; }","tryCatchPattern":"try {\n  reader.apply(iter);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Bad line:\")) {\n    log.error(\"Fix CRF input format: \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["Pre-validate every corpus line matches 'word label' with at least one space before feeding the reader.","Strip or blank junk lines in a preprocessing pass.","Keep delimiters consistent (spaces, not tabs) across corpus-generation scripts."],"tags":["data-format","nlp","input-validation","crf"],"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"}