{"record":{"id":"d6cad218d8d0e775","repo":"ssssssss-team/spider-flow","slug":"id-duplicate-id","errorCode":null,"errorMessage":"\" + id + \": Duplicate ID","messagePattern":"\" \\+ id \\+ \": Duplicate ID","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"spider-flow-web/src/main/resources/static/js/mxgraph/mxgraph.js","lineNumber":86560,"sourceCode":" * Function: addElement\r\n *\r\n * Adds the given element to <elements> if it has an ID.\r\n */\r\nmxCodec.prototype.addElement = function(node)\r\n{\r\n\tif (node.nodeType == mxConstants.NODETYPE_ELEMENT)\r\n\t{\r\n\t\tvar id = node.getAttribute('id');\r\n\t\t\r\n\t\tif (id != null)\r\n\t\t{\r\n\t\t\tif (this.elements[id] == null)\r\n\t\t\t{\r\n\t\t\t\tthis.elements[id] = node;\r\n\t\t\t}\r\n\t\t\telse if (this.elements[id] != node)\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(id + ': Duplicate ID');\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\tnode = node.firstChild;\r\n\t\r\n\twhile (node != null)\r\n\t{\r\n\t\tthis.addElement(node);\r\n\t\tnode = node.nextSibling;\r\n\t}\r\n};\r\n\r\n/**\r\n * Function: getId\r\n *\r\n * Returns the ID of the specified object. This implementation\r\n * calls <reference> first and if that returns null handles\r","sourceCodeStart":86542,"sourceCodeEnd":86578,"githubUrl":"https://github.com/ssssssss-team/spider-flow/blob/c799cca99c7d064673dc79e6ef06a08bbc0e292d/spider-flow-web/src/main/resources/static/js/mxgraph/mxgraph.js#L86542-L86578","documentation":"mxGraph's object registry (mxObjectCodec / codec element map) enforces unique IDs: when decoding, if an ID is already registered and maps to a different node, it throws Error(id + ': Duplicate ID'). Each cell/element ID in the model must be globally unique.","triggerScenarios":"Decoding an mxGraphModel (e.g. from saved XML) that contains two elements sharing the same `id` attribute, or registering two different nodes under the same id via the codec's elements map.","commonSituations":"Hand-edited or generated graph XML with repeated IDs, merging two diagrams whose ID sequences overlap, or backend serialization that resets/loops ID counters.","solutions":["Regenerate unique IDs in the graph XML before loading (e.g. mxGraphModel's editor or post-process the XML to reassign ids).","Fix the server-side/client-side ID generator so counters never repeat (use mxUtils/uuid-style generation).","If merging diagrams, remap IDs in the incoming document to avoid collisions."],"exampleFix":"// before (XML)\n<mxCell id=\"1\" .../>\n<mxCell id=\"1\" .../>\n// after\n<mxCell id=\"1\" .../>\n<mxCell id=\"2\" .../>","handlingStrategy":"validation","validationCode":"function validateUniqueIds(xmlDoc) {\n  var ids = {}, dup = [];\n  Array.prototype.forEach.call(xmlDoc.querySelectorAll('[id]'), function(el) {\n    if (ids[el.getAttribute('id')]) dup.push(el.getAttribute('id'));\n    ids[el.getAttribute('id')] = true;\n  });\n  return dup; // must be empty before decoding\n}","typeGuard":null,"tryCatchPattern":"try {\n  codec.decode(doc.documentElement, graph.getModel());\n} catch (e) {\n  if (/Duplicate ID/.test(e.message)) { rewriteDuplicateIds(xmlDoc); codec.decode(doc.documentElement, graph.getModel()); }\n  else throw e;\n}","preventionTips":["Never hand-edit graph XML ids; let mxGraph assign them.","Remap ids when merging or concatenating diagram documents.","Use a UUID-based id generator for server-side XML generation."],"tags":["mxgraph","duplicate-id","xml"],"backgroundTag":"invalid-identifier","analyzedSha":"c799cca99c7d064673dc79e6ef06a08bbc0e292d","analyzedAt":"2026-09-08T13:47:08.225Z","contentChangedAt":"2026-09-08T13:47:08.225Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}