{"record":{"id":"861472fe50fa715d","repo":"stanfordnlp/CoreNLP","slug":"creating-nondeterminism-while-inserting-arc-a-be","errorCode":null,"errorMessage":"Creating nondeterminism while inserting arc {a} because it already has arc {existing} {checkDeterminism}","messagePattern":"Creating nondeterminism while inserting arc (.+?) because it already has arc (.+?) (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/fsm/TransducerGraph.java","lineNumber":253,"sourceCode":"   * @return true if and only if it added Arc a to the graph.\n   *         determinism.\n   */\n  protected boolean addArc(Arc a) {\n    Object source = a.getSourceNode();\n    Object target = a.getTargetNode();\n    Object input = a.getInput();\n    if (source == null || target == null || input == null) {\n      return false;\n    }\n    // add to data structures\n    if (arcs.contains(a)) {\n      return false;\n    }\n    // it's new, so add to the rest of the data structures\n    // add to source and input map\n    Pair p = Generics.newPair(source, input);\n    if (arcsBySourceAndInput.containsKey(p) && checkDeterminism) {\n      throw new RuntimeException(\"Creating nondeterminism while inserting arc \" + a + \" because it already has arc \" + arcsBySourceAndInput.get(p) + checkDeterminism);\n    }\n    arcsBySourceAndInput.put(p, a);\n    Maps.putIntoValueHashSet(arcsBySource, source, a);\n    p = Generics.newPair(target, input);\n    Maps.putIntoValueHashSet(arcsByTargetAndInput, p, a);\n    Maps.putIntoValueHashSet(arcsByTarget, target, a);\n    Maps.putIntoValueHashSet(arcsByInput, input, a);\n    // add to arcs\n    arcs.add(a);\n    return true;\n  }\n\n  public boolean removeArc(Arc a) {\n    Object source = a.getSourceNode();\n    Object target = a.getTargetNode();\n    Object input = a.getInput();\n    // remove from arcs\n    if (!arcs.remove(a)) {","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/fsm/TransducerGraph.java#L235-L271","documentation":"TransducerGraph.addArc detects, when checkDeterminism is enabled, that an arc with the same (source, input) pair already exists, meaning inserting the new arc would make the graph nondeterministic. It throws a RuntimeException naming both the new arc and the existing conflicting arc.","triggerScenarios":"Calling addArc (directly or via addOnePathToGraph / graph-building code) to insert a second arc with the same source node and input label while determinism checking is on.","commonSituations":"Building a transducer from a corpus where the same prefix admits two different continuations; adding duplicate training paths; combining graphs where edges overlap.","solutions":["Remove or merge the duplicate arc before adding the new one","Construct the graph with checkDeterminism=false if nondeterminism is acceptable","Deduplicate input paths before addOnePathToGraph","Inspect the reported existing arc to understand the conflict"],"exampleFix":"// before\nTransducerGraph g = new TransducerGraph();\ng.addArc(source, target, input);\n// after\nTransducerGraph g = new TransducerGraph(false); // disable determinism checking\nif (!g.getArcBySourceAndInput(source, input)) g.addArc(source, target, input);","handlingStrategy":"validation","validationCode":"// Guard before adding: refuse a second arc for the same (source,input) pair\nif (graphHasArcFor(graph, source, input)) {\n  throw new IllegalStateException(\"Arc already exists for \" + source + \" -> \" + input);\n}\ngraph.addArc(source, target, input);","typeGuard":null,"tryCatchPattern":"try {\n  graph.addArc(source, target, input);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Creating nondeterminism\")) {\n    // merge or skip the conflicting arc\n  } else throw e;\n}","preventionTips":["Deduplicate training paths before building the graph","Construct with checkDeterminism=false only when nondeterminism is intended","Track (source,input) pairs in a set as you add arcs","Merge alternative continuations under a single arc when possible"],"tags":["java","fsm","graph","nondeterminism"],"backgroundTag":"invalid-state-transition","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"}