{"record":{"id":"0a4a7cd5e90c9c71","repo":"nathanmarz/storm","slug":"unsupported-encoding-of-object-of-class-obj-getclass-getname","errorCode":null,"errorMessage":"Unsupported encoding of object of class ${obj.getClass().getName()}","messagePattern":"Unsupported encoding of object of class (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"storm-netty/src/jvm/backtype/storm/messaging/netty/MessageEncoder.java","lineNumber":35,"sourceCode":" */\npackage backtype.storm.messaging.netty;\n\nimport org.jboss.netty.channel.Channel;\nimport org.jboss.netty.channel.ChannelHandlerContext;\nimport org.jboss.netty.handler.codec.oneone.OneToOneEncoder;\n\npublic class MessageEncoder extends OneToOneEncoder {    \n    @Override\n    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object obj) throws Exception {\n        if (obj instanceof ControlMessage) {\n            return ((ControlMessage)obj).buffer();\n        }\n\n        if (obj instanceof MessageBatch) {\n            return ((MessageBatch)obj).buffer();\n        } \n        \n        throw new RuntimeException(\"Unsupported encoding of object of class \"+obj.getClass().getName());\n    }\n\n\n}\n","sourceCodeStart":17,"sourceCodeEnd":40,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-netty/src/jvm/backtype/storm/messaging/netty/MessageEncoder.java#L17-L40","documentation":"MessageEncoder (a Netty OneToOneEncoder) only knows how to encode MessageBatch (and the control/established paths above it). If a pipeline hands it any other object type, it throws this RuntimeException at MessageEncoder.java:35 with the class name.","triggerScenarios":"Writing an object other than MessageBatch (e.g. raw byte[], String, TaskMessage directly) into the netty channel whose pipeline contains MessageEncoder.","commonSituations":"Custom code bypassing Client/Server and writing directly to the Channel; modified pipelines where messages skip the MessageBatch aggregation step; test harnesses sending Strings or byte arrays through the storm netty pipeline.","solutions":["Always send MessageBatch objects through the channel; batch TaskMessages first.","Route sends through Client.send instead of writing to the channel directly.","If a new message type is needed, add an instanceof branch in MessageEncoder that returns its encoded bytes."],"exampleFix":"// before\nchannel.write(messageBytes);\n// after\nMessageBatch batch = new MessageBatch(maxBatchSize);\nbatch.add(new TaskMessage(task, messageBytes));\nchannel.write(batch);","handlingStrategy":"type-guard","validationCode":"if (!(out instanceof MessageBatch)) {\n    throw new IllegalArgumentException(\"Only MessageBatch may be written to this channel\");\n}","typeGuard":"boolean isChannelEncodable(Object o) {\n    return o instanceof MessageBatch;\n}","tryCatchPattern":null,"preventionTips":["Send through Client.send rather than writing to the channel directly.","Always aggregate messages into a MessageBatch before channel writes.","Do not alter the netty pipeline to bypass MessageEncoder's expected input."],"tags":["netty","encoder","pipeline","messaging"],"backgroundTag":"type-mismatch","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"}