{"record":{"id":"2b3a2c05dbff4661","repo":"prestodb/presto","slug":"expected-a-class-type-for-javatype-but-got","errorCode":null,"errorMessage":"Expected a Class type for javaType, but got: ","messagePattern":"Expected a Class type for javaType, but got: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/GenericThriftCodec.java","lineNumber":40,"sourceCode":"import java.lang.reflect.Type;\n\nimport static com.facebook.presto.spi.StandardErrorCode.INVALID_ARGUMENTS;\nimport static com.facebook.presto.thrift.codec.ThriftCodecUtils.fromThrift;\nimport static com.facebook.presto.thrift.codec.ThriftCodecUtils.toThrift;\nimport static java.util.Objects.requireNonNull;\n\npublic class GenericThriftCodec<T>\n        implements ConnectorCodec<T>\n{\n    private final ThriftCodec<T> thriftCodec;\n\n    public GenericThriftCodec(ThriftCodecManager codecManager, Type javaType)\n    {\n        requireNonNull(codecManager, \"codecManager is null\");\n        requireNonNull(javaType, \"javaType is null\");\n\n        if (!(javaType instanceof Class<?>)) {\n            throw new IllegalArgumentException(\"Expected a Class type for javaType, but got: \" + javaType.getTypeName());\n        }\n\n        Class<?> clazz = (Class<?>) javaType;\n\n        this.thriftCodec = (ThriftCodec<T>) codecManager.getCodec(clazz);\n    }\n\n    @Override\n    public byte[] serialize(T value)\n    {\n        try {\n            return toThrift(value, thriftCodec);\n        }\n        catch (TProtocolException e) {\n            throw new PrestoException(INVALID_ARGUMENTS, \"Unable to serialize object of type \" + value.getClass().getSimpleName(), e);\n        }\n    }\n","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-thrift-connector-toolkit/src/main/java/com/facebook/presto/thrift/codec/GenericThriftCodec.java#L22-L58","documentation":"GenericThriftCodec requires the javaType argument to be a concrete Class so the ThriftCodecManager can resolve a codec for it. Passing a parameterized Type (e.g. a generic List<T> type token) or other Type implementation fails this check.","triggerScenarios":"new GenericThriftCodec(codecManager, someGenericType) where javaType is a ParameterizedType or GenericArrayType rather than a plain Class object.","commonSituations":"Registering codecs for generic Java types in thrift connector toolkit setup, or passing TypeToken.getType() results instead of raw classes.","solutions":["Pass the raw Class object (e.g. MyEvent.class) instead of a parameterized Type","Register a specific codec for the generic type with the ThriftCodecManager and wrap it directly","Use a dedicated codec class for the collection/generic type"],"exampleFix":"// before\nnew GenericThriftCodec(manager, new TypeToken<List<MyEvent>>(){}.getType());\n// after\nnew GenericThriftCodec(manager, MyEvent.class);","handlingStrategy":"type-guard","validationCode":"if (!(javaType instanceof Class<?>)) { throw new IllegalArgumentException(\"GenericThriftCodec requires a raw Class, got: \" + javaType.getTypeName()); }","typeGuard":"boolean isRawClass(Type t) { return t instanceof Class<?>; }","tryCatchPattern":"try { codec = new GenericThriftCodec<>(manager, javaType); } catch (IllegalArgumentException e) { log.error(\"Pass a raw Class to GenericThriftCodec\"); throw e; }","preventionTips":["Always pass Foo.class, never TypeToken.getType()","Avoid parameterized generics with GenericThriftCodec","Write codecs for element types, not collection types"],"tags":["thrift","codec","validation","thrift-connector-toolkit"],"backgroundTag":"invalid-argument-value","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}