{"record":{"id":"d4efd12d88632e64","repo":"hibernate/hibernate-orm","slug":"name-of-class-to-load-cannot-be-null","errorCode":null,"errorMessage":"Name of class to load cannot be null","messagePattern":"Name of class to load cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/internal/ClassLoaderAccessImpl.java","lineNumber":49,"sourceCode":"\t}\n\n\tpublic ClassLoaderAccessImpl(ClassLoader tempClassLoader, ServiceRegistry serviceRegistry) {\n\t\tthis( tempClassLoader, serviceRegistry.getService( ClassLoaderService.class ) );\n\t}\n\n\tpublic ClassLoaderAccessImpl(ClassLoaderService classLoaderService) {\n\t\tthis( null, classLoaderService );\n\t}\n\n\tpublic void injectTempClassLoader(ClassLoader jpaTempClassLoader) {\n\t\tthis.jpaTempClassLoader = jpaTempClassLoader;\n\t}\n\n\t@Override\n\t@SuppressWarnings(\"unchecked\")\n\tpublic Class<?> classForName(String name) {\n\t\tif ( name == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Name of class to load cannot be null\" );\n\t\t}\n\n\t\tif ( isSafeClass( name ) ) {\n\t\t\treturn classLoaderService.classForName( name );\n\t\t}\n\t\telse {\n\t\t\t// Could not determine that the given class is safe to load with live ClassLoader\n\t\t\tif ( jpaTempClassLoader == null ) {\n\t\t\t\tBOOT_LOGGER.noTempClassLoaderProvidedUsingLiveClassLoader( name );\n\t\t\t\treturn classLoaderService.classForName( name );\n\t\t\t}\n\t\t\telse {\n\t\t\t\ttry {\n\t\t\t\t\treturn jpaTempClassLoader.loadClass( name );\n\t\t\t\t}\n\t\t\t\tcatch (ClassNotFoundException e) {\n\t\t\t\t\tthrow new ClassLoadingException( name );\n\t\t\t\t}","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/internal/ClassLoaderAccessImpl.java#L31-L67","documentation":"ClassLoaderAccessImpl.classForName(name) is the gate through which all class loading during metadata processing goes, and it rejects a null name immediately with IllegalArgumentException 'Name of class to load cannot be null'. A null reaching it means some mapping or caller tried to resolve a class without actually having a class name.","triggerScenarios":"Passing null to ClassLoaderAccess.classForName from programmatic metadata or an integration; a mapping whose class-name resolution returned null and was forwarded unchecked (e.g. a hand-edited hbm.xml <class> without a usable name, or a reflection-based mapping where the lookup missed).","commonSituations":"Hand-edited XML mappings with missing or empty name attributes; generated mapping templates where a placeholder did not fill; custom Integrators/MetadataSourceProcessors forwarding unresolved names.","solutions":["Inspect the mapping identified in the stack trace and give the entity/component a real fully-qualified class name","Null-check the name at the call site and fail with a descriptive mapping error instead of calling classForName(null)","If dynamic map-backed entities are intended, configure them so no class name is resolved at all"],"exampleFix":"// before\nclassLoaderAccess.classForName(persistentClass.getClassName()); // may be null\n\n// after\nString cn = Objects.requireNonNull(\n        persistentClass.getClassName(),\n        \"entity has no class name: \" + persistentClass.getEntityName());\nclassLoaderAccess.classForName(cn);","handlingStrategy":"validation","validationCode":"if (name == null || name.isBlank()) {\n    throw new IllegalArgumentException(\n            \"Mapping must declare a class name, got: \" + mappingSource);\n}\nreturn classLoaderAccess.classForName(name);","typeGuard":"static boolean hasClassName(String name) {\n    return name != null && !name.isBlank();\n}","tryCatchPattern":null,"preventionTips":["Fail fast with a descriptive error whenever mapping resolution yields null","Validate hbm.xml documents against the bundled XSD in CI so nameless <class> elements are caught early"],"tags":["hibernate","classloading","mapping","null-check"],"backgroundTag":"null-class-name","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}