nathanmarz/storm · error · RuntimeException

Unsupported encoding of object of class

Error message

Unsupported encoding of object of class ${obj.getClass().getName()}

What it means

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.

Solutions

  1. Always send MessageBatch objects through the channel; batch TaskMessages first.
  2. Route sends through Client.send instead of writing to the channel directly.
  3. If a new message type is needed, add an instanceof branch in MessageEncoder that returns its encoded bytes.

Example fix

// before
channel.write(messageBytes);
// after
MessageBatch batch = new MessageBatch(maxBatchSize);
batch.add(new TaskMessage(task, messageBytes));
channel.write(batch);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(out instanceof MessageBatch)) {
    throw new IllegalArgumentException("Only MessageBatch may be written to this channel");
}

Type guard

boolean isChannelEncodable(Object o) {
    return o instanceof MessageBatch;
}

Prevention

When it happens

Trigger: Writing an object other than MessageBatch (e.g. raw byte[], String, TaskMessage directly) into the netty channel whose pipeline contains MessageEncoder.

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of nathanmarz/storm@cdb116e942 (2026-09-12). Data as JSON: /api/errors/0a4a7cd5e90c9c71. Report an issue: GitHub.

Appendix: source

Thrown at storm-netty/src/jvm/backtype/storm/messaging/netty/MessageEncoder.java:35

 */
package backtype.storm.messaging.netty;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;

public class MessageEncoder extends OneToOneEncoder {    
    @Override
    protected Object encode(ChannelHandlerContext ctx, Channel channel, Object obj) throws Exception {
        if (obj instanceof ControlMessage) {
            return ((ControlMessage)obj).buffer();
        }

        if (obj instanceof MessageBatch) {
            return ((MessageBatch)obj).buffer();
        } 
        
        throw new RuntimeException("Unsupported encoding of object of class "+obj.getClass().getName());
    }


}

View on GitHub (pinned to cdb116e942)