{"record":{"id":"9b15391bfd2c6224","repo":"stanfordnlp/CoreNLP","slug":"could-not-create-a-new-instance-of-test-id","errorCode":null,"errorMessage":"Could not create a new instance of test \" + id","messagePattern":"Could not create a new instance of test \" \\+ id","errorType":"exception","errorClass":"SsurgeonRuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/pred/SsurgTestManager.java","lineNumber":47,"sourceCode":"    if (instance == null)\n      instance = new SsurgTestManager();\n    return instance;\n  }\n\n  public void registerNodeTest(NodeTest nodeTestObj) {\n    nodeTests.put(nodeTestObj.getID(), nodeTestObj.getClass());\n  }\n\n  /**\n   * Given the id of the test, and the match name argument, returns a new instance\n   * of the given NodeTest, otherwise throws an exception if not available.\n   */\n  public NodeTest getNodeTest(String id, String matchName) {\n    try {\n      NodeTest test = (NodeTest) nodeTests.get(id).getConstructor(String.class).newInstance(matchName);\n      return test;\n    } catch (ReflectiveOperationException e) {\n      throw new SsurgeonRuntimeException(\"Could not create a new instance of test \" + id, e);\n    }\n  }\n}\n","sourceCodeStart":29,"sourceCodeEnd":51,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/pred/SsurgTestManager.java#L29-L51","documentation":"SsurgTestManager.getNodeTest instantiates a registered NodeTest class reflectively via a single-String constructor. If the lookup or construction fails (unknown id, no matching constructor, instantiation/access exceptions), it wraps the ReflectiveOperationException in a SsurgeonRuntimeException naming the test id.","triggerScenarios":"Calling getNodeTest with an id that is not registered in nodeTests (NPE wrapped as reflective failure context), or a registered class lacking a public (String) constructor or being abstract/non-instantiable.","commonSituations":"Custom NodeTest implementations that forgot the String constructor; registering a class but making it abstract; id string mismatch between the rules XML and the registry.","solutions":["Verify the id passed to getNodeTest is registered in the nodeTests map","Ensure the NodeTest class defines a public constructor taking a single String","Make the test class concrete and public; check the cause (getCause) for the exact reflective failure"],"exampleFix":"// before\npublic class MyTest extends NodeTest {\n  public MyTest(String matchName, String extra) { ... }\n}\n// after\npublic class MyTest extends NodeTest {\n  public MyTest(String matchName) { ... }\n}","handlingStrategy":"try-catch","validationCode":"if (!SsurgTestManager.hasTest(id)) { throw new IllegalArgumentException(\"Unknown test id: \" + id); }","typeGuard":"static boolean instantiable(Class<?> c) {\n  return !Modifier.isAbstract(c.getModifiers()) &&\n         Arrays.stream(c.getConstructors()).anyMatch(k -> k.getParameterCount() == 1 && k.getParameterTypes()[0] == String.class);\n}","tryCatchPattern":"try {\n  NodeTest t = manager.getNodeTest(id, matchName);\n} catch (SsurgeonRuntimeException e) {\n  log.error(\"Cannot build test \" + id + \": \" + e.getCause(), e);\n}","preventionTips":["Always give custom NodeTest classes a public (String) constructor","Keep test ids in the XML in sync with the registry","Inspect getCause() to distinguish unknown id from constructor problems"],"tags":["reflection","ssurgeon","instantiation"],"backgroundTag":"class-not-found","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"}