{"record":{"id":"4c33b48ec00501c5","repo":"nathanmarz/storm","slug":"fields-for-streamid-already-set","errorCode":null,"errorMessage":"Fields for ${streamId} already set","messagePattern":"Fields for (.+?) already set","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"storm-core/src/jvm/backtype/storm/topology/OutputFieldsGetter.java","lineNumber":43,"sourceCode":"\npublic class OutputFieldsGetter implements OutputFieldsDeclarer {\n    private Map<String, StreamInfo> _fields = new HashMap<String, StreamInfo>();\n\n    public void declare(Fields fields) {\n        declare(false, fields);\n    }\n\n    public void declare(boolean direct, Fields fields) {\n        declareStream(Utils.DEFAULT_STREAM_ID, direct, fields);\n    }\n\n    public void declareStream(String streamId, Fields fields) {\n        declareStream(streamId, false, fields);\n    }\n\n    public void declareStream(String streamId, boolean direct, Fields fields) {\n        if(_fields.containsKey(streamId)) {\n            throw new IllegalArgumentException(\"Fields for \" + streamId + \" already set\");\n        }\n        _fields.put(streamId, new StreamInfo(fields.toList(), direct));\n    }\n\n\n    public Map<String, StreamInfo> getFieldsDeclaration() {\n        return _fields;\n    }\n\n}","sourceCodeStart":25,"sourceCodeEnd":53,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-core/src/jvm/backtype/storm/topology/OutputFieldsGetter.java#L25-L53","documentation":"OutputFieldsGetter tracks declared streams in _fields; declareStream throws IllegalArgumentException if the same streamId is declared twice. Storm requires each stream id on a component to be declared exactly once. This is a topology-definition (user code) error thrown at topology declaration time.","triggerScenarios":"Calling declareStream twice with the same streamId; calling declare() on a component that also already used declareStream(\"default\", ...) for the default stream; an OutputFieldsDeclarer shared/reused across two components (e.g. a cached getter) so ids collide.","commonSituations":"Dynamic/stream-id built from variables that accidentally repeats; a base class declares the default stream and the subclass declares it again; reusing one OutputFieldsGetter object for multiple components in a builder helper.","solutions":["Declare each stream id only once per component; remove the duplicate declareStream call","If the default stream is declared via declare(), do not also call declareStream(\"default\", ...)","Use unique stream ids (e.g. prefix with component-specific names)","Check for a shared/reused OutputFieldsDeclarer instance and create a fresh one per component"],"exampleFix":"// before\ndeclarer.declareStream(\"default\", new Fields(\"a\"));\ndeclarer.declareStream(\"default\", new Fields(\"b\")); // throws\n// after\ndeclarer.declareStream(\"default\", new Fields(\"a\"));\ndeclarer.declareStream(\"secondary\", new Fields(\"b\"));","handlingStrategy":"validation","validationCode":"Set<String> declared = new HashSet<>();\nvoid safeDeclare(OutputFieldsDeclarer d, String streamId, Fields f) {\n    if (!declared.add(streamId))\n        throw new IllegalStateException(\"duplicate stream: \" + streamId);\n    d.declareStream(streamId, f);\n}","typeGuard":null,"tryCatchPattern":"try {\n    declarer.declareStream(streamId, fields);\n} catch (IllegalArgumentException e) {\n    if (!e.getMessage().contains(\"already set\")) throw e;\n    // log and skip duplicate declaration\n}","preventionTips":["Declare the default stream only via declare(), not declareStream(\"default\", ...)","Never reuse an OutputFieldsDeclarer across components","Keep stream-id constants in one place to avoid accidental collisions"],"tags":["topology","duplicate-declaration","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"}