{"record":{"id":"ac63dbc3ffb8869d","repo":"hibernate/hibernate-orm","slug":"value-to-extract-hashcode-from-cannot-be-null","errorCode":null,"errorMessage":"Value to extract hashCode from cannot be null","messagePattern":"Value to extract hashCode from cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java","lineNumber":227,"sourceCode":"\t * Retrieve the natural comparator for this type.\n\t */\n\tdefault Comparator<T> getComparator() {\n\t\t//noinspection unchecked\n\t\treturn Comparable.class.isAssignableFrom( getJavaTypeClass() )\n\t\t\t\t? ComparableComparator.INSTANCE\n\t\t\t\t: null;\n\t}\n\n\t/**\n\t * Extract a proper hash code for the given value.\n\t *\n\t * @param value The value for which to extract a hash code.\n\t *\n\t * @return The extracted hash code.\n\t */\n\tdefault int extractHashCode(T value) {\n\t\tif ( value == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Value to extract hashCode from cannot be null\" );\n\t\t}\n\t\treturn value.hashCode();\n\t}\n\n\t/**\n\t * Determine if two instances are equal\n\t *\n\t * @param one One instance\n\t * @param another The other instance\n\t *\n\t * @return True if the two are considered equal; false otherwise.\n\t */\n\tdefault boolean areEqual(T one, T another) {\n\t\treturn Objects.deepEquals( one, another );\n\t}\n\n\t/**\n\t * Whether to use {@link Object#equals(Object)} and {@link Object#hashCode()}","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/descriptor/java/JavaType.java#L209-L245","documentation":"JavaType.extractHashCode(T) is a default interface method that rejects null with IllegalArgumentException because there is no meaningful hash for a null domain value, then delegates to value.hashCode(). Hitting it means some Hibernate component asked the JavaType for the hash of a null — most commonly a custom JavaType/UserType that kept the default implementation and receives nulls during dirty checking or hash-based key computation.","triggerScenarios":"Custom JavaType implementations (registered via @JavaType/@Type) that do not override extractHashCode, used on nullable attributes where null reaches hash computation; null values in id or map-key positions typed with the custom type; wrapper types feeding null through.","commonSituations":"Introducing a custom type for a nullable column; null embedded-id components; collections compared or keyed through the custom type; Hibernate upgrades where hash-based dirty checking paths started calling this method.","solutions":["Override extractHashCode in your custom JavaType with a null-safe policy (e.g. return 0 for null)","Make areEqual and extractHashCode consistently null-aware so nulls never reach the default method","Check the stack trace to see which component (dirty checker, cache key, collection) passed null","If nulls are legitimate for the mapped data, fix the mapping so hash positions cannot be null"],"exampleFix":"// before: default method throws on null\n@Override\npublic int extractHashCode(MyType value) { // inherited default\n    ...\n}\n\n// after: null-safe override in your custom type\n@Override\npublic int extractHashCode(MyType value) {\n    return value == null ? 0 : value.hashCode();\n}","handlingStrategy":"validation","validationCode":"// before any manual hash use of a JavaType\nif (value == null) {\n    // skip hashing; Hibernate's own areEqual path handles null comparisons\n}","typeGuard":"static boolean hashable(Object v) { return v != null; }","tryCatchPattern":null,"preventionTips":["Make custom JavaTypes null-safe by default: override extractHashCode and areEqual together","Test custom types with null values before registering them","Do not use domain types without a null representation in hash-key positions"],"tags":["hibernate","custom-type","null","hashcode","java-type"],"backgroundTag":"null-argument-validation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}