{"record":{"id":"1550edb9123c358e","repo":"apache/dolphinscheduler","slug":"encode-msg-is-null","errorCode":null,"errorMessage":"encode msg is null","messagePattern":"encode msg is null","errorType":"exception","errorClass":"RemoteException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/protocal/TransporterEncoder.java","lineNumber":33,"sourceCode":" * limitations under the License.\n */\n\npackage org.apache.dolphinscheduler.extract.base.protocal;\n\nimport org.apache.dolphinscheduler.extract.base.exception.RemoteException;\n\nimport io.netty.buffer.ByteBuf;\nimport io.netty.channel.ChannelHandler.Sharable;\nimport io.netty.channel.ChannelHandlerContext;\nimport io.netty.handler.codec.MessageToByteEncoder;\n\n@Sharable\npublic class TransporterEncoder extends MessageToByteEncoder<Transporter> {\n\n    @Override\n    protected void encode(ChannelHandlerContext ctx, Transporter transporter, ByteBuf out) {\n        if (transporter == null) {\n            throw new RemoteException(\"encode msg is null\");\n        }\n        out.writeByte(Transporter.MAGIC);\n        out.writeByte(Transporter.VERSION);\n\n        // write header\n        byte[] header = transporter.getHeader().toBytes();\n        out.writeInt(header.length);\n        out.writeBytes(header);\n\n        // write body\n        byte[] body = transporter.getBody();\n        out.writeInt(body.length);\n        out.writeBytes(body);\n    }\n\n}\n","sourceCodeStart":15,"sourceCodeEnd":50,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/protocal/TransporterEncoder.java#L15-L50","documentation":"TransporterEncoder.encode throws a RemoteException when asked to encode a null Transporter message. Netty invoked the encoder with no outbound message, which indicates an internal bug: a null object reached the outbound pipeline.","triggerScenarios":"A null object is written to the Netty channel (ctx.writeAndFlush(null)) and Netty's MessageToByteEncoder hands it to encode() despite the generic type match.","commonSituations":"RPC invocation returns/produces a null response object that is written directly to the channel; async callback code writing an uninitialized result; custom code writing to the channel without a null check.","solutions":["Find the caller writing a null to the channel and fix it to never write a null Transporter","Add a null check before ctx.writeAndFlush(msg) in the sending code path","Log the call site producing the null response and fix the handler that should have populated it","Ensure failed RPC invocations produce a valid error Transporter rather than null"],"exampleFix":"// before\nTransporter transporter = buildResponse(request); // may return null\nctx.writeAndFlush(transporter);\n// after\nTransporter transporter = buildResponse(request);\nif (transporter != null) {\n    ctx.writeAndFlush(transporter);\n}","handlingStrategy":"type-guard","validationCode":"// guard every outbound write\nif (msg == null) {\n    throw new IllegalStateException(\"Refusing to write null Transporter to channel \" + ctx.channel());\n}","typeGuard":"static boolean isSendable(Transporter t) {\n    return t != null && t.getHeader() != null;\n}","tryCatchPattern":"try {\n    ctx.writeAndFlush(transporter);\n} catch (RemoteException e) {\n    if (\"encode msg is null\".equals(e.getMessage())) {\n        // log the pipeline path that produced a null message; fix the producer\n    }\n}","preventionTips":["Never return null from response-building methods; return an error Transporter instead","Null-check messages before writeAndFlush","Cover async handlers with tests that fail when a null message is produced"],"tags":["netty","encoder","null-pointer","rpc"],"backgroundTag":"null-argument","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}