stanfordnlp/CoreNLP · error · SsurgeonRuntimeException

Could not create a new instance of test " + id

Error message

Could not create a new instance of test " + id

What it means

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.

Solutions

  1. Verify the id passed to getNodeTest is registered in the nodeTests map
  2. Ensure the NodeTest class defines a public constructor taking a single String
  3. Make the test class concrete and public; check the cause (getCause) for the exact reflective failure

Example fix

// before
public class MyTest extends NodeTest {
  public MyTest(String matchName, String extra) { ... }
}
// after
public class MyTest extends NodeTest {
  public MyTest(String matchName) { ... }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!SsurgTestManager.hasTest(id)) { throw new IllegalArgumentException("Unknown test id: " + id); }

Type guard

static boolean instantiable(Class<?> c) {
  return !Modifier.isAbstract(c.getModifiers()) &&
         Arrays.stream(c.getConstructors()).anyMatch(k -> k.getParameterCount() == 1 && k.getParameterTypes()[0] == String.class);
}

Try / catch

try {
  NodeTest t = manager.getNodeTest(id, matchName);
} catch (SsurgeonRuntimeException e) {
  log.error("Cannot build test " + id + ": " + e.getCause(), e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/9b15391bfd2c6224. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/pred/SsurgTestManager.java:47

    if (instance == null)
      instance = new SsurgTestManager();
    return instance;
  }

  public void registerNodeTest(NodeTest nodeTestObj) {
    nodeTests.put(nodeTestObj.getID(), nodeTestObj.getClass());
  }

  /**
   * Given the id of the test, and the match name argument, returns a new instance
   * of the given NodeTest, otherwise throws an exception if not available.
   */
  public NodeTest getNodeTest(String id, String matchName) {
    try {
      NodeTest test = (NodeTest) nodeTests.get(id).getConstructor(String.class).newInstance(matchName);
      return test;
    } catch (ReflectiveOperationException e) {
      throw new SsurgeonRuntimeException("Could not create a new instance of test " + id, e);
    }
  }
}

View on GitHub (pinned to 1b7edd19c4)