{"record":{"id":"4c42d7b1fb407c39","repo":"stanfordnlp/CoreNLP","slug":"can-t-handle-this-type-of-generaldataset","errorCode":null,"errorMessage":"Can't handle this type of GeneralDataset.","messagePattern":"Can't handle this type of GeneralDataset\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/classify/GeneralDataset.java","lineNumber":411,"sourceCode":"      labels[j] = tmpl;\n\n      E tmpE = sideInformation.get(randIndex);\n      sideInformation.set(randIndex, sideInformation.get(j));\n      sideInformation.set(j, tmpE);\n    }\n  }\n\n  public GeneralDataset<L,F> sampleDataset(long randomSeed, double sampleFrac, boolean sampleWithReplacement) {\n    int sampleSize = (int)(this.size()*sampleFrac);\n    Random rand = new Random(randomSeed);\n    GeneralDataset<L,F> subset;\n    if (this instanceof RVFDataset) {\n      subset = new RVFDataset<>();\n    } else if (this instanceof Dataset) {\n      subset = new Dataset<>();\n    }\n    else {\n      throw new RuntimeException(\"Can't handle this type of GeneralDataset.\");\n    }\n    if (sampleWithReplacement) {\n      for(int i = 0; i < sampleSize; i++){\n        int datumNum = rand.nextInt(this.size());\n        subset.add(this.getDatum(datumNum));\n      }\n    } else {\n      Set<Integer> indicedSampled = Generics.newHashSet();\n      while (subset.size() < sampleSize) {\n        int datumNum = rand.nextInt(this.size());\n        if (!indicedSampled.contains(datumNum)) {\n          subset.add(this.getDatum(datumNum));\n          indicedSampled.add(datumNum);\n        }\n      }\n    }\n    return subset;\n  }","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/classify/GeneralDataset.java#L393-L429","documentation":"RuntimeException from GeneralDataset.sampleDataset when the dataset is neither an RVFDataset nor a Dataset. Sampling only knows how to instantiate those two concrete types, so custom GeneralDataset subclasses are rejected.","triggerScenarios":"Thrown at src/edu/stanford/nlp/classify/GeneralDataset.java:411 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Sample from a Dataset or RVFDataset instead of a custom subclass","Override or extend sampleDataset for custom GeneralDataset types","Convert the dataset to a supported type before sampling"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}