{"record":{"id":"eaeb7bda68d79ced","repo":"stanfordnlp/CoreNLP","slug":"wanted-singletonpredictor-got-o-getclass","errorCode":null,"errorMessage":"Wanted SingletonPredictor, got ${o.getClass()}","messagePattern":"Wanted SingletonPredictor, got (.+?)","errorType":"validation","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java","lineNumber":1043,"sourceCode":"        removeClusterSet.add(c.clusterID);\n      }\n    }\n    for (int removeId : removeClusterSet){\n      document.corefClusters.remove(removeId);\n    }\n    for(Mention m : removeSet){\n      document.positions.remove(m);\n    }\n  }\n\n  public static LogisticClassifier<String, String> getSingletonPredictorFromSerializedFile(String serializedFile) {\n    try {\n      ObjectInputStream ois = IOUtils.readStreamFromString(serializedFile);\n      Object o = ois.readObject();\n      if (o instanceof LogisticClassifier<?, ?>) {\n        return (LogisticClassifier<String, String>) o;\n      }\n      throw new ClassCastException(\"Wanted SingletonPredictor, got \" + o.getClass());\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    } catch (ClassNotFoundException e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n  /** Remove singleton clusters */\n  public static List<List<Mention>> filterMentionsWithSingletonClusters(Document document, List<List<Mention>> mentions)\n  {\n\n    List<List<Mention>> res = new ArrayList<>(mentions.size());\n    for (List<Mention> ml:mentions) {\n      List<Mention> filtered = new ArrayList<>();\n      for (Mention m:ml) {\n        CorefCluster cluster = document.corefClusters.get(m.corefClusterID);\n        if (cluster != null && cluster.getCorefMentions().size() > 1) {\n          filtered.add(m);","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java#L1025-L1061","documentation":"This ClassCastException is thrown by SieveCoreferenceSystem.loadSingletonPredictor when the object deserialized from the singleton-predictor model file is not a LogisticClassifier as expected. It indicates the serialized file's contents do not match what this code path expects, typically because the wrong model file was supplied or the model format changed between CoreNLP versions.","triggerScenarios":"Calling the method that loads the singleton predictor model (via IOUtils.readStreamFromString on serializedFile) when the file contains any object that is not an instance of LogisticClassifier.","commonSituations":"Pointing -singletonModel (or dcoref properties) at a wrong or corrupted serialized file; using a predictor serialized by a different CoreNLP version whose class changed; confusing the singleton predictor file with another dcoref model file.","solutions":["Verify the serialized file passed to the loader is the singleton predictor model produced by SingletonPredictor.saveToSerialized","Regenerate the model file with a matching CoreNLP version","Inspect the file's class with a small test deserialization to confirm what it contains","Update CoreNLP so model and code versions match"],"exampleFix":"// before\nprops.setProperty(\"singletonModel\", \"my-coref-model.ser\");\n// after\nprops.setProperty(\"singletonModel\", \"singleton-predictor.ser\"); // file saved by SingletonPredictor.saveToSerialized","handlingStrategy":"try-catch","validationCode":"// Before loading, sanity-check the model file exists\nFile f = new File(modelPath);\nif (!f.isFile() || f.length() == 0) throw new IllegalArgumentException(\"Bad singleton model file: \" + modelPath);","typeGuard":"if (o instanceof LogisticClassifier<?, ?>) { /* safe cast */ } else { throw new IllegalArgumentException(\"Wrong model class: \" + o.getClass()); }","tryCatchPattern":"try {\n  predictor = SieveCoreferenceSystem.loadSingletonPredictor(path);\n} catch (ClassCastException e) {\n  throw new IllegalStateException(\"Singleton model file has wrong content; regenerate it with SingletonPredictor.saveToSerialized\", e);\n} catch (RuntimeIOException e) {\n  throw new IllegalStateException(\"Cannot read singleton model: \" + path, e);\n}","preventionTips":["Serialize the model with SingletonPredictor.saveToSerialized from the same CoreNLP version","Keep model files versioned alongside the CoreNLP version","Add a startup deserialization self-check in CI","Never point singletonModel at unrelated serialized objects"],"tags":["java","deserialization","classcastexception","dcoref"],"backgroundTag":"incompatible-source-type","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"}