{"record":{"id":"328e36128e1ae99a","repo":"nathanmarz/storm","slug":"bolt-has-already-been-declared-for-id-id","errorCode":null,"errorMessage":"Bolt has already been declared for id ${id}","messagePattern":"Bolt has already been declared for id (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"storm-core/src/jvm/backtype/storm/topology/TopologyBuilder.java","lineNumber":212,"sourceCode":"        validateUnusedId(id);\n        initCommon(id, spout, parallelism_hint);\n        _spouts.put(id, spout);\n        return new SpoutGetter(id);\n    }\n\n    public void setStateSpout(String id, IRichStateSpout stateSpout) {\n        setStateSpout(id, stateSpout, null);\n    }\n\n    public void setStateSpout(String id, IRichStateSpout stateSpout, Number parallelism_hint) {\n        validateUnusedId(id);\n        // TODO: finish\n    }\n\n\n    private void validateUnusedId(String id) {\n        if(_bolts.containsKey(id)) {\n            throw new IllegalArgumentException(\"Bolt has already been declared for id \" + id);\n        }\n        if(_spouts.containsKey(id)) {\n            throw new IllegalArgumentException(\"Spout has already been declared for id \" + id);\n        }\n        if(_stateSpouts.containsKey(id)) {\n            throw new IllegalArgumentException(\"State spout has already been declared for id \" + id);\n        }\n    }\n\n    private ComponentCommon getComponentCommon(String id, IComponent component) {\n        ComponentCommon ret = new ComponentCommon(_commons.get(id));\n        \n        OutputFieldsGetter getter = new OutputFieldsGetter();\n        component.declareOutputFields(getter);\n        ret.set_streams(getter.getFieldsDeclaration());\n        return ret;        \n    }\n    ","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-core/src/jvm/backtype/storm/topology/TopologyBuilder.java#L194-L230","documentation":"TopologyBuilder.validateUnusedId throws IllegalArgumentException when setBolt is called with an id that is already registered as a bolt. Storm component ids must be unique across the topology, so reusing an id is rejected immediately at topology construction.","triggerScenarios":"Calling builder.setBolt(id, ...) with an id previously passed to setBolt; a loop that re-declares bolts with a fixed or wrongly incremented id; topology code executed twice with the same builder.","commonSituations":"Copy-pasted bolt declarations with the same string id; ids generated without counters (e.g. constant \"bolt\"); rebuilding a topology on the same builder after a validation failure.","solutions":["Rename one of the bolts so every component id is unique","Generate ids programmatically (e.g. \"bolt-\" + index) to avoid collisions","Use a fresh TopologyBuilder for each topology build instead of reusing one","Search your topology code for duplicate setBolt calls with the same id"],"exampleFix":"// before\nbuilder.setBolt(\"split\", new SplitBolt());\nbuilder.setBolt(\"split\", new CountBolt()); // throws\n// after\nbuilder.setBolt(\"split\", new SplitBolt());\nbuilder.setBolt(\"count\", new CountBolt());","handlingStrategy":"validation","validationCode":"Set<String> used = new HashSet<>();\nvoid safeBolt(TopologyBuilder b, String id, IRichBolt bolt) {\n    if (!used.add(id))\n        throw new IllegalStateException(\"duplicate component id: \" + id);\n    b.setBolt(id, bolt);\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder.setBolt(id, bolt);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().contains(\"already been declared\")) throw e;\n    // handle duplicate id: rename or skip\n}","preventionTips":["Assign unique, descriptive ids to every component","Never reuse a populated TopologyBuilder","In generated topologies, assert id uniqueness before building"],"tags":["topology","duplicate-id","storm"],"backgroundTag":"invalid-argument-value","analyzedSha":"cdb116e942666973bc4eaa0df098d5bab82739e7","analyzedAt":"2026-09-12T14:30:00.714Z","contentChangedAt":"2026-09-12T14:30:00.714Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}