{"record":{"id":"f9e1283cb336acdf","repo":"hibernate/hibernate-orm","slug":"illegal-to-add-basicjavatype-with-null-java-type","errorCode":null,"errorMessage":"Illegal to add BasicJavaType with null Java type","messagePattern":"Illegal to add BasicJavaType with null Java type","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeRegistry.java","lineNumber":55,"sourceCode":"\tprivate static final Logger LOG = Logger.getLogger( JavaTypeRegistry.class );\n\n\tprivate final TypeConfiguration typeConfiguration;\n\tprivate final ConcurrentHashMap<String, JavaType<?>> descriptorsByTypeName = new ConcurrentHashMap<>();\n\n\tpublic JavaTypeRegistry(TypeConfiguration typeConfiguration) {\n\t\tthis.typeConfiguration = typeConfiguration;\n\t\tJavaTypeBaseline.prime( this );\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// baseline descriptors\n\n\t@Override\n\tpublic void addBaselineDescriptor(JavaType<?> descriptor) {\n\t\tfinal var javaType = descriptor.getJavaType();\n\t\tif ( javaType == null ) {\n\t\t\tthrow new IllegalStateException( \"Illegal to add BasicJavaType with null Java type\" );\n\t\t}\n\t\taddBaselineDescriptor( javaType, descriptor );\n\t}\n\n\t@Override\n\tpublic void addBaselineDescriptor(Type describedJavaType, JavaType<?> descriptor) {\n\t\tperformInjections( descriptor );\n\t\tdescriptorsByTypeName.put( describedJavaType.getTypeName(), descriptor );\n\t}\n\n\tprivate void performInjections(JavaType<?> descriptor) {\n\t\tif ( descriptor instanceof TypeConfigurationAware typeConfigurationAware ) {\n\t\t\t// would be nice to make the JavaType for an entity, e.g., aware of the TypeConfiguration\n\t\t\ttypeConfigurationAware.setTypeConfiguration( typeConfiguration );\n\t\t}\n\t}\n\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/spi/JavaTypeRegistry.java#L37-L73","documentation":"While priming the JavaTypeRegistry, Hibernate rejects any JavaType whose getJavaType() returns null. addBaselineDescriptor(JavaType) requires the descriptor to know its own Java type because the registry is keyed by type name; a null-typed descriptor makes registration impossible and throws IllegalStateException.","triggerScenarios":"A TypeContributor or integrator calling typeConfiguration.getJavaTypeRegistry().addBaselineDescriptor(descriptor) where the descriptor was built without a Class/Type (null passed to the constructor) or does not override getJavaType(); custom AbstractJavaType subclasses for generic types where no Class object is available at construction.","commonSituations":"Custom integrations registering descriptors of parameterized types; copy-pasted descriptor scaffolding with a null super(...) argument; upgrades where getJavaType() became nullable and old code stopped overriding it.","solutions":["Construct the descriptor with its Class: super(MyType.class)","Override getJavaType()/getJavaTypeClass() to return a non-null Type/Class","Use the two-argument overload addBaselineDescriptor(Type, JavaType) to supply the described type explicitly","If the type is generic, register a ParameterizedJavaType or pass the raw Class instead of null"],"exampleFix":"// before\npublic class MyTypeJavaType extends AbstractClassJavaType<MyType> {\n    public MyTypeJavaType() { super(null); } // getJavaType() == null -> IllegalStateException\n}\n\n// after\npublic class MyTypeJavaType extends AbstractClassJavaType<MyType> {\n    public MyTypeJavaType() { super(MyType.class); }\n}","handlingStrategy":"validation","validationCode":"static void assertRegistrable(JavaType<?> descriptor) {\n    if (descriptor.getJavaType() == null)\n        throw new IllegalStateException(\n            \"descriptor \" + descriptor + \" has null Java type; register with addBaselineDescriptor(Type, JavaType)\");\n}\n// call before registry.addBaselineDescriptor(descriptor)","typeGuard":"static boolean registrable(JavaType<?> descriptor) {\n    return descriptor.getJavaType() != null;\n}","tryCatchPattern":"try {\n    registry.addBaselineDescriptor(descriptor);\n} catch (IllegalStateException e) {\n    // log which contributor supplied the null-typed descriptor and skip it with a warning\n    LOG.warn(\"Skipping null-typed descriptor from contributor: {}\", descriptor, e);\n}","preventionTips":["Always pass the represented Class to JavaType constructors","Unit-test custom TypeContributors by priming a fresh TypeConfiguration","Use addBaselineDescriptor(Type, JavaType) when the described type is generic"],"tags":["hibernate","orm","registry","custom-type","integrator"],"backgroundTag":"type-registration-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}