{"record":{"id":"4acd61597371b6c6","repo":"hibernate/hibernate-orm","slug":"can-t-get-java-type-class-from-type-type","errorCode":null,"errorMessage":"Can't get java type class from type: \" + type","messagePattern":"Can't get java type class from type: \" \\+ type","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java","lineNumber":898,"sourceCode":"\t}\n\n\tpublic static <T> Class<T> getClass(java.lang.reflect.Type type) {\n\t\tif ( type == null ) {\n\t\t\treturn null;\n\t\t}\n\t\telse if ( type instanceof Class<?> ) {\n\t\t\treturn (Class<T>) type;\n\t\t}\n\t\telse if ( type instanceof ParameterizedType parameterizedType ) {\n\t\t\treturn (Class<T>) parameterizedType.getRawType();\n\t\t}\n\t\telse if ( type instanceof TypeVariable<?> typeVariable ) {\n\t\t\treturn getClass( typeVariable.getBounds()[0] );\n\t\t}\n\t\telse if ( type instanceof WildcardType wildcardType ) {\n\t\t\treturn getClass( wildcardType.getUpperBounds()[0] );\n\t\t}\n\t\tthrow new UnsupportedOperationException( \"Can't get java type class from type: \" + type );\n\t}\n\n\tpublic static Class<?> getPropertyType(Member member) {\n\t\tif (member instanceof Field field) {\n\t\t\treturn field.getType();\n\t\t}\n\t\telse if (member instanceof Method method) {\n\t\t\treturn method.getReturnType();\n\t\t}\n\t\telse {\n\t\t\tthrow new AssertionFailure(\"member should have been a method or field\");\n\t\t}\n\t}\n\n\tpublic static boolean isClass(Class<?> resultClass) {\n\t\treturn !resultClass.isArray()\n\t\t\t&& !resultClass.isPrimitive()\n\t\t\t&& !resultClass.isEnum()","sourceCodeStart":880,"sourceCodeEnd":916,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java#L880-L916","documentation":"ReflectHelper.getClass(java.lang.reflect.Type) reduces a reflective Type to its raw Class. It handles plain Class, ParameterizedType (raw type), TypeVariable (first bound), and WildcardType (first upper bound). Every other shape — most notably GenericArrayType such as List<String>[] and hand-rolled Type implementations — falls through to UnsupportedOperationException.","triggerScenarios":"Resolving a mapped attribute, query return, or generic signature where the reflected Type is a generic array (e.g., an attribute declared List<String>[], whose GenericArrayType component is itself generic), or calling ReflectHelper.getClass(type) directly with such a Type.","commonSituations":"Entities or embeddables with array-of-generic attributes; generic super-type walking that lands on T[] bounds; custom java.lang.reflect.Type implementations plugged into metadata resolution; migrations to Hibernate 6 exposing exotic generic signatures that earlier versions tolerated.","solutions":["Replace array-of-generic attributes with a concrete collection or plain array (List<String>[] -> List<String> or String[]).","Give the attribute an explicit type annotation (@JdbcTypeCode/@Type) so Hibernate never has to reduce the generic Type to a Class.","If you call getClass(Type) yourself, pre-reduce GenericArrayType by recursing on getGenericComponentType()."],"exampleFix":"// before\n@Embeddable\npublic class ReportFilter {\n    private List<String>[] labels; // GenericArrayType -> UnsupportedOperationException\n}\n\n// after\n@Embeddable\npublic class ReportFilter {\n    @ElementCollection\n    private List<String> labels;\n}","handlingStrategy":"type-guard","validationCode":"static Class<?> safeClassFor(java.lang.reflect.Type t) {\n    if (t instanceof java.lang.reflect.GenericArrayType gat) {\n        Class<?> component = safeClassFor(gat.getGenericComponentType());\n        return java.lang.reflect.Array.newInstance(component, 0).getClass();\n    }\n    return org.hibernate.internal.util.ReflectHelper.getClass(t);\n}","typeGuard":"static boolean reducibleToClass(java.lang.reflect.Type t) {\n    if (t instanceof Class<?> || t instanceof java.lang.reflect.ParameterizedType\n            || t instanceof java.lang.reflect.TypeVariable<?> || t instanceof java.lang.reflect.WildcardType) {\n        return true;\n    }\n    if (t instanceof java.lang.reflect.GenericArrayType gat) {\n        return reducibleToClass(gat.getGenericComponentType());\n    }\n    return false;\n}","tryCatchPattern":"try {\n    Class<?> raw = ReflectHelper.getClass(type);\n} catch (UnsupportedOperationException e) {\n    // type is a GenericArrayType or custom Type; restructure the attribute or reduce it yourself\n}","preventionTips":["Avoid generic array attributes in mapped types.","Prefer collections over arrays in generic mapped hierarchies.","Give exotic attributes explicit @JdbcTypeCode/@Type so generic reduction never runs."],"tags":["hibernate","reflection","generics","type-resolution"],"backgroundTag":"unsupported-generic-type-resolution","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}