{"record":{"id":"ec34a5428d985dba","repo":"stanfordnlp/CoreNLP","slug":"target-of-a-dependency-was-null-edge-edge","errorCode":null,"errorMessage":"Target of a dependency was null!\nEdge: ${edge}","messagePattern":"Target of a dependency was null!\nEdge: (.+?)","errorType":"exception","errorClass":"FailedSerializationError","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java","lineNumber":2478,"sourceCode":"      }\n      if (word.index() < 0 && in.getIndex() >= 0) {\n        word.setIndex(in.getIndex());\n      }\n\n      nodes.put(in.getIndex(), in.getEmptyIndex(), in.getCopyAnnotation(), word);\n      graph.addVertex(word);\n      orderedNodes.add(word);\n    }\n\n    // add all edges to the actual graph\n    for(CoreNLPProtos.DependencyGraph.Edge ie: proto.getEdgeList()){\n      IndexedWord source = nodes.get(ie.getSource(), ie.getSourceEmpty(), ie.getSourceCopy());\n      if (source == null) {\n        throw new FailedSerializationError(\"Source of a dependency was null!\\nEdge: \" + ie);\n      }\n      IndexedWord target = nodes.get(ie.getTarget(), ie.getTargetEmpty(), ie.getTargetCopy());\n      if (target == null) {\n        throw new FailedSerializationError(\"Target of a dependency was null!\\nEdge: \" + ie);\n      }\n      synchronized (globalLock) {\n        // this is not thread-safe: there are static fields in GrammaticalRelation\n        if (!ie.hasDep()) {\n          throw new FailedSerializationError(\"Protobuf dependency edge was null!\\nEdge: \" + ie);\n        }\n        GrammaticalRelation rel = GrammaticalRelation.valueOf(fromProto(ie.getLanguage()), ie.getDep());\n        graph.addEdge(source, target, rel, 1.0, ie.hasIsExtra() && ie.getIsExtra());\n      }\n    }\n\n    if (proto.getRootNodeCount() > 0) {\n      Collection<IndexedWord> roots = proto.getRootNodeList().stream().map(idx -> orderedNodes.get(idx)).collect(Collectors.toList());\n      graph.setRoots(roots);\n    } else if (proto.getRootCount() > 0) {\n      // assume empty nodes and copy nodes can't be the root\n      // this is actually not true: there are examples in the UD Estonian EWT treebank\n      // which have empty nodes as the root of the enhanced graph","sourceCodeStart":2460,"sourceCodeEnd":2496,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java#L2460-L2496","documentation":"Thrown by ProtobufAnnotationSerializer when a DependencyGraph edge's target node (by index, empty-flag, copy-flag triple) cannot be found in the node map built from the proto message. This indicates a corrupt or incompletely populated serialized dependency graph, so deserialization fails with FailedSerializationError.","triggerScenarios":"Deserializing a CoreNLPProtos message where DependencyGraph.Edge.getTarget() refers to a node absent from the proto's node list (mismatched nodeIndex/nodeEmpty/nodeCopy).","commonSituations":"Protobufs generated by incompatible CoreNLP versions, partially written/truncated serialized pipelines, or hand-crafted protos missing node entries.","solutions":["Reserialize the annotation with a matching CoreNLP version so node/edge indexes agree.","Add the missing target node to the proto's node list with the exact nodeIndex/nodeEmpty/nodeCopy the edge references.","Log and inspect the offending Edge printed in the error to identify the dangling node reference."],"exampleFix":"// before: edge points at target 7 with no such node\nEdge.newBuilder().setSource(1).setTarget(7).build();\n// after: emit the target node too\ngraph.addNodesBuilder().setNodeIndex(7).setWord(\"cat\");\ngraph.addEdgesBuilder().setSource(1).setTarget(7).setDep(\"obj\");","handlingStrategy":"validation","validationCode":"boolean allEdgeTargetsPresent(CoreNLPProtos.DependencyGraph g) {\n  Set<Integer> idx = g.getNodeList().stream().map(CoreNLPProtos.Node::getNodeIndex).collect(Collectors.toSet());\n  return g.getEdgeList().stream().allMatch(e -> idx.contains(e.getTarget()));\n}","typeGuard":"if (nodes.get(ie.getTarget(), ie.getTargetEmpty(), ie.getTargetCopy()) == null) return null;","tryCatchPattern":"try {\n  return serializer.fromProto(proto);\n} catch (ProtobufAnnotationSerializer.FailedSerializationError e) {\n  if (e.getMessage().startsWith(\"Target of a dependency was null\")) {\n    return fallbackDeserializeIgnoringGraph(proto);\n  }\n  throw e;\n}","preventionTips":["Validate node/edge referential integrity before deserializing third-party protos.","Keep producer and consumer CoreNLP versions in sync.","Checksum or re-serialize large annotation archives to detect truncation."],"tags":["protobuf","serialization","dependency-graph","corenlp"],"backgroundTag":"protobuf-unmarshal-failed","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"}