{"record":{"id":"b5d2157950239281","repo":"stanfordnlp/CoreNLP","slug":"protobuf-dependency-edge-was-null-edge-edge","errorCode":null,"errorMessage":"Protobuf dependency edge was null!\nEdge: ${edge}","messagePattern":"Protobuf dependency edge was null!\nEdge: (.+?)","errorType":"exception","errorClass":"FailedSerializationError","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java","lineNumber":2483,"sourceCode":"      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\n      Collection<IndexedWord> roots = proto.getRootList().stream().map(rootI -> nodes.get(rootI, 0, 0)).collect(Collectors.toList());\n      graph.setRoots(roots);\n    } else {\n      // Roots were not saved away\n      // compute root nodes if non-empty","sourceCodeStart":2465,"sourceCodeEnd":2501,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/ProtobufAnnotationSerializer.java#L2465-L2501","documentation":"Thrown by ProtobufAnnotationSerializer when a protobuf DependencyGraph edge has no 'dep' field set (the grammatical relation name), even though its endpoints resolve. Reconstructing the GrammaticalRelation requires the relation string, so the serializer aborts.","triggerScenarios":"Deserializing a proto where Edge.hasDep() is false — i.e., the edge was built without calling setDep(), or the field was cleared.","commonSituations":"Custom pipeline tools that write dependency edges without relation labels, protobufs produced by older/other NLP tooling that omits relation names, or fields lost during proto manipulation.","solutions":["Set the dep field on every edge (e.g. setDep(\"nsubj\")) before serializing.","Reject/repair such edges upstream: skip edges lacking a dep or assign a default like 'dep'.","Verify the producing code path always populates the relation, e.g. when converting a SemanticGraph to proto."],"exampleFix":"// before\nEdge.newBuilder().setSource(1).setTarget(2).build();\n// after\nEdge.newBuilder().setSource(1).setTarget(2).setDep(\"nsubj\").build();","handlingStrategy":"validation","validationCode":"boolean allEdgesHaveDep(CoreNLPProtos.DependencyGraph g) {\n  return g.getEdgeList().stream().allMatch(CoreNLPProtos.DependencyGraph.Edge::hasDep);\n}","typeGuard":"if (!ie.hasDep() || ie.getDep().isEmpty()) return null;","tryCatchPattern":"try {\n  return serializer.fromProto(proto);\n} catch (ProtobufAnnotationSerializer.FailedSerializationError e) {\n  if (e.getMessage().contains(\"dependency edge was null\")) {\n    log.warn(\"Edge without relation label; skipping graph\");\n    return annotationWithoutGraph(proto);\n  }\n  throw e;\n}","preventionTips":["Always setDep() when constructing DependencyGraph edges.","Run a schema/lint pass over generated protos that requires the dep field.","Preserve edges through SemanticGraph->proto conversions by copying the relation value."],"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"}