hibernate/hibernate-orm · error · NullPointerException

name was null attempting to build qualified name

Error message

name was null attempting to build qualified name

What it means

StringHelper.qualifyConditionally(prefix, name) qualifies only when the prefix is non-empty; the name itself is mandatory. A null name throws NullPointerException with this message immediately, while a null or empty prefix is legal and returns the name unqualified. The asymmetry is deliberate: prefix optional, name required.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java:589

	public static boolean isNotBlank(@Nullable String string) {
		return string != null && !string.isBlank();
	}

	public static boolean isBlank(@Nullable String string) {
		return string == null || string.isBlank();
	}

	public static String qualify(String prefix, String name) {
		if ( name == null || prefix == null ) {
			throw new NullPointerException( "prefix or name were null attempting to build qualified name" );
		}
		return prefix + '.' + name;
	}

	public static String qualifyConditionally(String prefix, String name) {
		if ( name == null ) {
			throw new NullPointerException( "name was null attempting to build qualified name" );
		}
		return isEmpty( prefix ) ? name : prefix + '.' + name;
	}

	/**
	 * Qualifies {@code name} with {@code prefix} separated by a '.' if<ul>
	 *     <li>{@code name} is not already qualified</li>
	 *     <li>{@code prefix} is not null</li>
	 * </ul>
	 *
	 * @apiNote Similar to {@link #qualifyConditionally}, except that here we explicitly
	 * check whether {@code name} is already qualified.
	 */
	public static String qualifyConditionallyIfNot(String prefix, String name) {
		if ( name == null ) {
			throw new NullPointerException( "name was null attempting to build qualified name" );
		}
		if ( name.indexOf( '.' ) > 0 || isEmpty( prefix ) ) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Null-check the name before calling and throw a meaningful error identifying the caller and the missing element.
  2. Fix the upstream producer so qualified names are never null.
  3. If both arguments are optional at your call site, branch explicitly instead of relying on the helper's contract.

Example fix

// before
String q = StringHelper.qualifyConditionally(tableSchema, tableName); // tableName == null -> NPE

// after
if (tableName == null) throw new IllegalStateException("table name missing for schema " + tableSchema);
String q = StringHelper.qualifyConditionally(tableSchema, tableName);
Defensive patterns

Strategy: validation

Validate before calling

if (name == null) {
    throw new IllegalStateException("name was null building a qualified name for prefix " + prefix);
}
String q = StringHelper.qualifyConditionally(prefix, name);

Prevention

When it happens

Trigger: Calling qualifyConditionally(prefix, null), or an internal Hibernate call site where the element being qualified (table, column, or property name) resolved to null upstream while the prefix was correctly empty or absent.

Common situations: Programmatic metadata built with a null name argument; custom naming code feeding null names; refactors that changed argument order so a nullable prefix/nullable value lands in the name slot.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/278386016084175b. Report an issue: GitHub.