{"record":{"id":"3c48395cd000a7bf","repo":"eclipse-vertx/vert.x","slug":"invalid-type-for-shareddata-data-structure-obj","errorCode":null,"errorMessage":"Invalid type for shareddata data structure: ${obj.getClass().getName()}","messagePattern":"Invalid type for shareddata data structure: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/shareddata/impl/Checker.java","lineNumber":57,"sourceCode":"    .add(String.class)\n    .add(Integer.class)\n    .add(Long.class)\n    .add(Boolean.class)\n    .add(Double.class)\n    .add(Float.class)\n    .add(Short.class)\n    .add(Byte.class)\n    .add(Character.class)\n    .add(BigInteger.class)\n    .add(BigDecimal.class)\n    .build()\n    .collect(toSet());\n\n  static void checkType(Object obj) {\n    Objects.requireNonNull(obj, \"null not allowed for shareddata data structure\");\n    // All immutables and byte arrays are Serializable by the platform\n    if (!(obj instanceof Serializable || obj instanceof Shareable || obj instanceof ClusterSerializable)) {\n      throw new IllegalArgumentException(\"Invalid type for shareddata data structure: \" + obj.getClass().getName());\n    }\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  static <T> T copyIfRequired(T obj) {\n    Object result;\n    if (obj == null) {\n      // Happens with putIfAbsent\n      result = null;\n    } else if (IMMUTABLE_TYPES.contains(obj.getClass())) {\n      result = obj;\n    } else if (obj instanceof byte[]) {\n      result = copyByteArray((byte[]) obj);\n    } else if (obj instanceof Shareable) {\n      result = ((Shareable) obj).copy();\n    } else if (obj instanceof ClusterSerializable) {\n      result = copyClusterSerializable((ClusterSerializable) obj);\n    } else if (obj instanceof Serializable) {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/shareddata/impl/Checker.java#L39-L75","documentation":"Vert.x SharedData only allows values that can be safely shared across threads/cluster members. Checker.checkType validates that an object placed into a shared data structure is Serializable, Shareable, or ClusterSerializable; otherwise it throws IllegalArgumentException naming the offending class.","triggerScenarios":"Calling put/putForEviction on a LocalMap or an AsyncMap with a key or value whose class implements none of java.io.Serializable, io.vertx.core.shareddata.Shareable, or io.vertx.core.cluster.ClusterSerializable (e.g. a POJO without implements Serializable).","commonSituations":"Developers put arbitrary domain objects (config beans, builders like java.lang.Object graphs, non-serializable library types) into a LocalMap or cluster-wide AsyncMap; or after a refactor the value class lost its Serializable interface.","solutions":["Make the stored class implement Serializable (or Shareable for mutable types with an efficient copy strategy).","If the type is an array-like payload, store byte[] or a Buffer (Buffer is ClusterSerializable).","Store a serializable representation (JSON via JsonObject, a String, or a primitive wrapper) instead of the raw object.","If the object must stay non-serializable, keep it in an ordinary ConcurrentMap rather than SharedData."],"exampleFix":"// before\nlocalMap.put(\"cfg\", new MyConfig()); // MyConfig not serializable -> IllegalArgumentException\n// after\npublic class MyConfig implements Serializable { ... }\nlocalMap.put(\"cfg\", new MyConfig());","handlingStrategy":"validation","validationCode":"static boolean isShareableType(Object o) {\n  return o instanceof java.io.Serializable\n      || o instanceof io.vertx.core.shareddata.Shareable\n      || o instanceof io.vertx.core.cluster.ClusterSerializable;\n}\nif (!isShareableType(value)) throw new IllegalArgumentException(\"cannot store \" + value.getClass() + \" in shared data\");","typeGuard":"static boolean isShareableType(Object o) {\n  return o instanceof java.io.Serializable\n      || o instanceof io.vertx.core.shareddata.Shareable\n      || o instanceof io.vertx.core.cluster.ClusterSerializable;\n}","tryCatchPattern":"try {\n  map.put(key, value);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Invalid type\")) {\n    throw new IllegalStateException(\"Value type \" + value.getClass().getName() + \" is not shareable\");\n  }\n  throw e;\n}","preventionTips":["Make every domain class stored in shared data implement Serializable or Shareable at definition time.","Prefer Buffer/JsonObject/boxed primitives which are already supported.","Add a unit test that puts each stored type into a LocalMap.","Never assume lambda/graph-heavy objects (streams, builders) are shareable."],"tags":["shared-data","java","illegal-argument","serialization"],"backgroundTag":"incompatible-source-type","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}