{"record":{"id":"3586f03c7e7b70a6","repo":"stanfordnlp/CoreNLP","slug":"bad-data-format","errorCode":null,"errorMessage":"Bad data format: ","messagePattern":"Bad data format: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/RVFDataset.java","lineNumber":779,"sourceCode":"          lines.add(line);\n        dataset.add(svmLightLineToRVFDatum(line));\n      }\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    } finally {\n      IOUtils.closeIgnoringExceptions(in);\n    }\n    return dataset;\n  }\n\n  public static RVFDatum<String, String> svmLightLineToRVFDatum(String l) {\n    l = l.replaceFirst(\"#.*$\", \"\"); // remove any trailing comments\n    String[] line = l.split(\"\\\\s+\");\n    ClassicCounter<String> features = new ClassicCounter<>();\n    for (int i = 1; i < line.length; i++) {\n      String[] f = line[i].split(\":\");\n      if (f.length != 2) {\n        throw new IllegalArgumentException(\"Bad data format: \" + l);\n      }\n      double val = Double.parseDouble(f[1]);\n      features.incrementCount(f[0], val);\n    }\n    return new RVFDatum<>(features, line[0]);\n  }\n\n  // todo [cdm 2012]: This duplicates the functionality of the methods above. Should be refactored.\n  /**\n   * Read SVM-light formatted data into this dataset.\n   *\n   * A strict SVM-light format is expected, where labels and features are both\n   * encoded as integers. These integers are converted into the dataset label\n   * and feature types using the indexes stored in this dataset.\n   *\n   * @param file The file from which the data should be read.\n   */\n  public void readSVMLightFormat(File file) {","sourceCodeStart":761,"sourceCodeEnd":797,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/RVFDataset.java#L761-L797","documentation":"When parsing an SVM-light format line, every token after the label must be 'feature:value'. If any token splits on ':' into other than exactly 2 parts, svmLightLineToRVFDatum throws IllegalArgumentException(\"Bad data format: \" + wholeLine). It signals malformed input format rather than an I/O problem.","triggerScenarios":"Reading an SVMLight file where a feature token lacks ':value' (bare feature id), has extra colons (e.g. 'f1:2:3' or URLs as feature names), or the line has stray tokens such as malformed comments not stripped by the leading '#' rule.","commonSituations":"Hand-edited SVM-light files; exporting from another tool with different feature naming containing colons; Windows line endings or trailing comments misformatted; accidentally passing a non-SVMLight file (e.g. ARFF or CSV) to the reader.","solutions":["Inspect the line printed in the message and fix the offending token to 'feature:numericValue' format","Remove or escape colons in feature names (rename features, e.g. replace ':' with '_') before export","Ensure the file is genuinely in SVM-light format: label first, then 'feat:value' pairs, '# comment' trailing only","Pre-validate lines in your pipeline with a regex like ^\\S+(\\s+[^:\\s]+:[0-9.eE+-]+)*$ before calling the reader"],"exampleFix":"// before\n// file line: label f1 f2:3\nlabel f1 f2:3\n// after\n// each feature must carry a value\nlabel f1:1 f2:3","handlingStrategy":"validation","validationCode":"Pattern svmLine = Pattern.compile(\"^\\\\S+(\\\\s+[^:\\\\s]+:[0-9.eE+-]+)*(\\\\s*#.*)?$\");\ntry (BufferedReader r = new BufferedReader(new FileReader(path))) {\n  String line; int n = 0;\n  while ((line = r.readLine()) != null) {\n    if (!line.trim().isEmpty() && !svmLine.matcher(line).matches())\n      throw new IllegalStateException(\"Malformed SVMLight line \" + (n+1) + \": \" + line);\n    n++;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  RVFDataset<String,String> ds = new RVFDataset<>(path, -1);\n} catch (IllegalArgumentException e) {\n  logger.severe(\"SVMLight parse failure: \" + e.getMessage()); // message includes the bad line\n  throw e;\n}","preventionTips":["Validate a sample of the file against SVM-light syntax before full load","Sanitize feature names (strip or replace ':') at export time","Confirm the file is SVM-light format, not CSV/ARFF, before passing to this reader"],"tags":["java","stanford-nlp","machine-learning","parsing","format-validation"],"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"}