spring-projects/spring-framework · error · InvalidPropertyException

Invalid property '{propertyName}' of bean class [{beanClass.

Error message

Invalid property '{propertyName}' of bean class [{beanClass.getName()}]: Getter for property '{actualName}' threw exception

What it means

Thrown by getPropertyValue when invoking the property's getter raised an InvocationTargetException (the getter threw). Spring unwraps it into InvalidPropertyException naming the actual property and preserving the target exception as the cause, so callers see a uniform property-access error rather than raw reflection noise.

Source

Thrown at spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java:695

					}
					indexedPropertyName.append(PROPERTY_KEY_PREFIX).append(key).append(PROPERTY_KEY_SUFFIX);
				}
			}
			return value;
		}
		catch (InvalidPropertyException ex) {
			throw ex;
		}
		catch (IndexOutOfBoundsException ex) {
			throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
					"Index of out of bounds in property path '" + propertyName + "'", ex);
		}
		catch (NumberFormatException | TypeMismatchException ex) {
			throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
					"Invalid index in property path '" + propertyName + "'", ex);
		}
		catch (InvocationTargetException ex) {
			throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
					"Getter for property '" + actualName + "' threw exception", ex);
		}
		catch (Exception ex) {
			throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
					"Illegal attempt to get property '" + actualName + "' threw exception", ex);
		}
	}


	/**
	 * Return the {@link PropertyHandler} for the specified {@code propertyName}, navigating
	 * if necessary. Return {@code null} if not found rather than throwing an exception.
	 * @param propertyName the property to obtain the descriptor for
	 * @return the property descriptor for the specified property,
	 * or {@code null} if not found
	 * @throws BeansException in case of introspection failure
	 */
	protected @Nullable PropertyHandler getPropertyHandler(String propertyName) throws BeansException {

View on GitHub (pinned to 69bf83ad71)

Solutions

  1. Inspect getCause() of the InvalidPropertyException to find the real exception from the getter and fix that root cause.
  2. Make the getter null-safe / defensive so it does not throw during property access.
  3. Ensure required collaborators/state are set before the property is accessed (initialize dependencies first).
  4. Avoid heavy or side-effecting logic inside getters used by BeanWrapper; move it to a service method.

Example fix

// before
public Address getAddress() {
  return address.getStreet().length(); // NPE if address null
}

// after
public Address getAddress() {
  return address; // plain accessor; logic moved out
Defensive patterns

Strategy: try-catch

Validate before calling

BeanWrapper w = new BeanWrapperImpl(bean);
// best-effort: ensure dependencies the getter needs are set first
// (no static guarantee a getter won't throw; keep getters simple)
if (!w.isReadableProperty("x")) return null;
return w.getPropertyValue("x");

Try / catch

try {
    return wrapper.getPropertyValue("x");
} catch (InvalidPropertyException ex) {
    Throwable cause = ex.getCause() != null ? ex.getCause().getCause() : null;
    // log cause; decide whether to treat as absent value or rethrow
    if (cause instanceof IllegalStateException) return null;
    throw ex;
}

Prevention

When it happens

Trigger: getPropertyValue("x") where getX() throws — e.g. throws IllegalStateException because a dependency is unset, returns via a field lazily initialized with failing logic, or a computed getter that divides by zero / NPEs.

Common situations: Getter with non-trivial logic that fails when state is incomplete; Lombok-generated getter that delegates to a null collaborator; entity getter calling a detached Hibernate proxy after session close; defensive getter that throws on invalid internal state during binding.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/7b3e96b984a80652. Report an issue: GitHub.