{"record":{"id":"a47efb215807ca76","repo":"apache/druid","slug":"cannot-create-type-s","errorCode":null,"errorMessage":"Cannot create type [%s]","messagePattern":"Cannot create type \\[(.+?)\\]","errorType":"exception","errorClass":"IAE","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/ExprEval.java","lineNumber":621,"sourceCode":"          }\n          return ofArray(type, array);\n        }\n\n        if (value instanceof Object[]) {\n          Object[] inputArray = (Object[]) value;\n          Object[] array = new Object[inputArray.length];\n          int i = 0;\n          for (Object o : inputArray) {\n            array[i++] = ExprEval.ofType(elementType, o).value();\n          }\n          return ofArray(type, array);\n        }\n        // in a better world, we might get an object that matches the type signature for arrays and could do a switch\n        // statement here, but this is not that world yet, and things that are array typed might also be non-arrays,\n        // e.g. we might get a String instead of String[], so just fallback to bestEffortOf\n        return bestEffortOf(value).castTo(type);\n    }\n    throw new IAE(\"Cannot create type [%s]\", type);\n  }\n\n  @Nullable\n  public static Number computeNumber(@Nullable String value)\n  {\n    if (value == null) {\n      return null;\n    }\n    if (Evals.asBoolean(value)) {\n      return 1.0;\n    }\n    if (value.equalsIgnoreCase(\"false\")) {\n      return 0.0;\n    }\n    Number rv;\n    Long v = GuavaUtils.tryParseLong(value);\n    // Do NOT use ternary operator here, because it makes Java to convert Long to Double\n    if (v != null) {","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/ExprEval.java#L603-L639","documentation":"ExprEval.ofType converts a deserialized value into an ExprEval of the requested type. For a null-typed or otherwise unhandled ExpressionType it falls through the switch and throws IAE 'Cannot create type'. Arrays and non-array mismatches are handled by bestEffortOf+castTo, so this only fires for types entirely outside the supported set.","triggerScenarios":"Calling ExprEval.ofType(type, value) with an ExpressionType whose registry kind is not handled (e.g. a null-typed type or a newly added type not yet supported).","commonSituations":"Deserializing values with a corrupted or unexpected type signature; custom code constructing ExpressionType instances outside the standard registry; version skew where a newer type is read by older code.","solutions":["Use a supported ExpressionType (LONG, LONG_ARRAY, DOUBLE, DOUBLE_ARRAY, STRING, STRING_ARRAY, COMPLEX, etc.) when calling ofType","If the input value may mismatch, call ExprEval.bestEffortOf(value).castTo(type) yourself instead of ofType","Check the serialized type signature producing the value; fix the writer side"],"exampleFix":"// before\nExprEval.ofType(ExpressionType.fromTypeFull(NullType.NAME), value);\n// after\nExprEval.bestEffortOf(value).castTo(ExpressionType.STRING);","handlingStrategy":"type-guard","validationCode":"switch (type.getFactory()) {\n  case LONG: case LONG_ARRAY: case DOUBLE: case DOUBLE_ARRAY:\n  case STRING: case STRING_ARRAY: case COMPLEX: /* ok */ break;\n  default: throw new IllegalArgumentException(\"unsupported type \" + type);\n}","typeGuard":null,"tryCatchPattern":"try {\n  eval = ExprEval.ofType(type, value);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot create type\")) {\n    eval = ExprEval.bestEffortOf(value).castTo(ExpressionType.STRING);\n  } else { throw e; }\n}","preventionTips":["Only pass ExpressionType values from the standard registry","Prefer bestEffortOf().castTo() for uncertain inputs","Guard against version skew on newly added types"],"tags":["expressions","deserialization","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}