{"record":{"id":"7bcedc0a103c526d","repo":"apache/hadoop","slug":"cannot-wrap-class","errorCode":null,"errorMessage":"Cannot wrap ${class}","messagePattern":"Cannot wrap (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RpcWritable.java","lineNumber":59,"sourceCode":" * Anything marked public is solely for access by SaslRpcClient\n */\n// note\n@InterfaceAudience.Private\npublic abstract class RpcWritable implements Writable {\n\n  static RpcWritable wrap(Object o) {\n    if (o instanceof RpcWritable) {\n      return (RpcWritable)o;\n    } else if (o instanceof Message) {\n      // hadoop shaded protobuf\n      return new ProtobufWrapper((Message)o);\n    } else if (ProtobufWrapperLegacy.isUnshadedProtobufMessage(o)) {\n      // unshaded protobuf\n      return new ProtobufWrapperLegacy(o);\n    } else if (o instanceof Writable) {\n      return new WritableWrapper((Writable)o);\n    }\n    throw new IllegalArgumentException(\"Cannot wrap \" + o.getClass());\n  }\n\n  // don't support old inefficient Writable methods.\n  @Override\n  public final void readFields(DataInput in) throws IOException {\n    throw new UnsupportedOperationException();\n  }\n  @Override\n  public final void write(DataOutput out) throws IOException {\n    throw new UnsupportedOperationException();\n  }\n\n  // methods optimized for reduced intermediate byte[] allocations.\n  abstract void writeTo(ResponseBuffer out) throws IOException;\n  abstract <T> T readFrom(ByteBuffer bb) throws IOException;\n\n  // adapter for Writables. Used for RPC_BUILTIN calls.\n  static class WritableWrapper extends RpcWritable {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/RpcWritable.java#L41-L77","documentation":"RpcWritable.wrap adapts an object for IPC serialization and accepts exactly four shapes: an RpcWritable, a shaded-protobuf Message (ProtobufWrapper), an unshaded-protobuf Message (ProtobufWrapperLegacy), or a Writable (WritableWrapper). Anything else yields IllegalArgumentException(\"Cannot wrap <class>\") — the object handed to the RPC layer for writing is not serializable by any supported engine.","triggerScenarios":"A protocol method whose request/response type is a plain Java type (String, Map, POJO) that is neither Writable nor a protobuf-generated Message; protobuf classes compiled against a protobuf runtime that matches neither the shaded nor unshaded branch; passing a response object of the wrong type through custom RPC plumbing.","commonSituations":"Hand-designed RPC protocols that ignore the Writable/protobuf constraint; mixing shaded and unshaded generated protobuf classes in one classpath; convenience methods accidentally left in a protocol interface; protobuf version upgrades leaving stale generated classes.","solutions":["Change the offending protocol method's payload type to a Writable implementation or a protobuf-generated Message compiled with the same (shaded) runtime Hadoop uses.","Read the class name in the message — it names the exact object that failed to wrap, pointing at the specific protocol method.","Verify generated protobuf classes come from the same protoc/runtime generation as the deployed Hadoop (shaded org.apache.hadoop.thirdparty.protobuf vs unshaded com.google.protobuf)."],"exampleFix":"// before\npublic interface MyProtocol {\n  String getStatus(); // Cannot wrap class java.lang.String\n}\n// after\npublic interface MyProtocol {\n  StatusResponseProto getStatus(); // protobuf Message (or a Writable implementation)\n}","handlingStrategy":"validation","validationCode":"static boolean ipcSerializable(Object o) {\n  return o instanceof Writable\n      || o instanceof org.apache.hadoop.thirdparty.protobuf.Message\n      || o instanceof com.google.protobuf.Message;\n}\n\n// before putting a response on the wire:\nif (!ipcSerializable(payload)) {\n  throw new IllegalArgumentException(\n      \"protocol payload not IPC-serializable: \" + payload.getClass());\n}","typeGuard":"static boolean isIpcSerializable(Object o) {\n  return o instanceof Writable\n      || o instanceof org.apache.hadoop.thirdparty.protobuf.Message\n      || o instanceof com.google.protobuf.Message;\n}","tryCatchPattern":null,"preventionTips":["Restrict RPC protocol interfaces to protobuf Messages or Writable types only.","Run a smoke RPC test over every protocol method when designing a new protocol.","Generate protobuf classes with the same protoc/runtime family as the deployed Hadoop (shaded vs unshaded)."],"tags":["rpc","serialization","protobuf","writable","protocol"],"backgroundTag":"unsupported-serialization-type","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}