{"record":{"id":"4c7496782adfebe5","repo":"alibaba/spring-ai-alibaba","slug":"internal-error-typereference-constructed-without","errorCode":null,"errorMessage":"Internal error: TypeReference constructed without actual type information","messagePattern":"Internal error: TypeReference constructed without actual type information","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/utils/TypeRef.java","lineNumber":51,"sourceCode":" * implementation of <code>Comparable</code> (any such generic interface would do, as long\n * as it forces a method with generic type to be implemented). to ensure that a Type\n * argument is indeed given.\n * <p>\n * Usage is by sub-classing: here is one way to instantiate reference to generic type\n * <code>List&lt;Integer></code>: <pre>\n *   var TypeRef = new TypeRef&lt;List&lt;Integer>>() { };\n * </pre> which can be passed to methods that accept TypeReference.\n *\n * @param <T>\n */\npublic abstract class TypeRef<T> implements Comparable<TypeRef<T>> {\n\n\tprotected final Type _type;\n\n\tprotected TypeRef() {\n\t\tType superClass = this.getClass().getGenericSuperclass();\n\t\tif (superClass instanceof Class) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Internal error: TypeReference constructed without actual type information\");\n\t\t}\n\t\telse {\n\t\t\tthis._type = ((ParameterizedType) superClass).getActualTypeArguments()[0];\n\t\t}\n\t}\n\n\tpublic Type getType() {\n\t\treturn this._type;\n\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\tpublic Optional<T> cast(Object obj) {\n\t\treturn erasureOf(this._type).filter(c -> c.isInstance(obj)).map(c -> (T) obj);\n\t}\n\n\tpublic static Optional<Class<?>> erasureOf(Type t) {\n\t\tif (t instanceof Class<?> c) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/utils/TypeRef.java#L33-L69","documentation":"TypeRef's protected constructor reads the generic superclass's type argument to capture the referenced type. If the subclass is constructed without type parameters (a raw or anonymous non-parameterized subclass), getGenericSuperclass() returns a plain Class and this IllegalArgumentException is thrown. It is a developer misuse error of the type-token pattern.","triggerScenarios":"new TypeRef() { } without a type argument, or instantiating a raw TypeRef subclass that does not encode a generic parameter, e.g. class MyRef extends TypeRef (no <T>).","commonSituations":"Copying a Jackson TypeReference-style snippet and forgetting the <T>; generating subclasses with erased generics; IDE quick-fix creating a non-generic subclass.","solutions":["Always subclass with an explicit type parameter: new TypeRef<Map<String,Object>>() {}.","Declare the subclass as class X extends TypeRef<Foo>, not TypeRef.","Reuse a single constant TypeRef instance instead of creating raw ones inline."],"exampleFix":"// before\nTypeRef ref = new TypeRef() {};\n// after\nTypeRef<Map<String,Object>> ref = new TypeRef<Map<String,Object>>() {};","handlingStrategy":"validation","validationCode":"// ensure the anonymous subclass carries a generic parameter\nTypeRef<Map<String,Object>> ref = new TypeRef<Map<String,Object>>() {};\nif (ref.getClass().getGenericSuperclass() instanceof Class) {\n  throw new IllegalArgumentException(\"TypeRef missing type parameter\");\n}","typeGuard":"boolean isUsableTypeRef(TypeRef<?> ref) {\n  return !(ref.getClass().getGenericSuperclass() instanceof Class);\n}","tryCatchPattern":"try {\n  use(ref);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"TypeReference constructed without\")) {\n    ref = new TypeRef<Map<String,Object>>() {}; // recreate with type argument\n  }\n}","preventionTips":["Always write new TypeRef<T>() {} with an explicit type argument.","Never instantiate raw TypeRef or TypeRef<?> without a body capturing T.","Store shared TypeRef constants instead of ad-hoc raw instances."],"tags":["generics","type-reference","developer-error"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}