stanfordnlp/CoreNLP · error · FailedSerializationError

Source of a dependency was null! Edge

Error message

Source of a dependency was null!
Edge: ${edge}

What it means

Thrown by ProtobufAnnotationSerializer when deserializing a protobuf DependencyGraph: an edge references a source node (by index, empty-flag, and copy-flag) that is not present in the node map built from the proto. The serializer treats this as an unfixable inconsistency in the serialized annotation and aborts via FailedSerializationError.

Solutions

  1. Regenerate the protobuf annotation with the same CoreNLP version that will deserialize it.
  2. Inspect the failing Edge (printed in the message) and add the missing source node to the proto's node list before deserializing.
  3. If building protos manually, ensure every edge endpoint is also present in DependencyGraph.node with matching nodeIndex/nodeEmpty/nodeCopy values.

Example fix

// before: manually built edge referencing node index 5 that was never added
Edge.newBuilder().setSource(5).setTarget(2).build();
// after: add the node first
graph.addNodesBuilder().setNodeIndex(5).setWord("dog");
graph.addEdgesBuilder().setSource(5).setTarget(2).setDep("nsubj");
Defensive patterns

Strategy: validation

Validate before calling

boolean edgeNodesPresent(CoreNLPProtos.DependencyGraph g) {
  Set<Long> keys = new HashSet<>();
  for (var n : g.getNodeList()) keys.add(nodeKey(n));
  return g.getEdgeList().stream().allMatch(e -> keys.contains((long) e.getSource()));
}

Type guard

if (nodes.get(ie.getSource(), ie.getSourceEmpty(), ie.getSourceCopy()) == null) return null;

Try / catch

try {
  Annotation ann = serializer.fromProto(proto);
} catch (ProtobufAnnotationSerializer.FailedSerializationError e) {
  log.error("Corrupt dependency graph proto: " + e.getMessage());
  throw new IllegalArgumentException("Malformed serialized annotation", e);
}

Prevention

When it happens

Trigger: Calling ProtobufAnnotationSerializer.fromProto / readAnnotation on a CoreNLPProtos message whose DependencyGraph.Edge.getSource() points to a node index/empty/copy triple never added via the edge list's node entries.

Common situations: Hand-constructed or truncated protobuf messages, messages written by a different CoreNLP version with a mismatched node indexing scheme, or third-party tools generating dependency protos without emitting all nodes.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java:2474

        word.setDocID(docid);
      }
      if (word.sentIndex() < 0 && in.getSentenceIndex() >= 0) {
        word.setSentIndex(in.getSentenceIndex());
      }
      if (word.index() < 0 && in.getIndex() >= 0) {
        word.setIndex(in.getIndex());
      }

      nodes.put(in.getIndex(), in.getEmptyIndex(), in.getCopyAnnotation(), word);
      graph.addVertex(word);
      orderedNodes.add(word);
    }

    // add all edges to the actual graph
    for(CoreNLPProtos.DependencyGraph.Edge ie: proto.getEdgeList()){
      IndexedWord source = nodes.get(ie.getSource(), ie.getSourceEmpty(), ie.getSourceCopy());
      if (source == null) {
        throw new FailedSerializationError("Source of a dependency was null!\nEdge: " + ie);
      }
      IndexedWord target = nodes.get(ie.getTarget(), ie.getTargetEmpty(), ie.getTargetCopy());
      if (target == null) {
        throw new FailedSerializationError("Target of a dependency was null!\nEdge: " + ie);
      }
      synchronized (globalLock) {
        // this is not thread-safe: there are static fields in GrammaticalRelation
        if (!ie.hasDep()) {
          throw new FailedSerializationError("Protobuf dependency edge was null!\nEdge: " + ie);
        }
        GrammaticalRelation rel = GrammaticalRelation.valueOf(fromProto(ie.getLanguage()), ie.getDep());
        graph.addEdge(source, target, rel, 1.0, ie.hasIsExtra() && ie.getIsExtra());
      }
    }

    if (proto.getRootNodeCount() > 0) {
      Collection<IndexedWord> roots = proto.getRootNodeList().stream().map(idx -> orderedNodes.get(idx)).collect(Collectors.toList());
      graph.setRoots(roots);

View on GitHub (pinned to 1b7edd19c4)