spring-projects/spring-framework · error · InvalidPropertyException

Getter for property '${actualName}' threw exception

Error message

Getter for property '${actualName}' threw exception

What it means

Catch block in getPropertyValue(PropertyTokenHolder) for InvocationTargetException thrown by the property getter (ph.getValue()). The getter executed reflectively but threw an application-level exception; Spring rewraps it as InvalidPropertyException 'Getter for property ... threw exception'. The actual cause is attached as the exception's cause for diagnosis.

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 e8729d0438)

Solutions

  1. Inspect the wrapped exception cause to find which getter line threw and fix that code path.
  2. Ensure the bean's internal state is fully initialized before the property is read.
  3. Guard the getter itself against null/invalid state rather than throwing.
  4. If accessing a lazy/proxy entity, make sure the owning session/context is open.

Example fix

// before
public String getCity() { return address.getCity(); } // NPE if address == null

// after
public String getCity() { return address != null ? address.getCity() : null; }
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure bean state is fully initialized before reading:
if (bean.getAddress() != null) {
    wrapper.getPropertyValue("address.city");
}

Type guard

static boolean getterIsSafe(Object bean, String getter) {
    try { bean.getClass().getMethod(getter).invoke(bean); return true; }
    catch (Exception ex) { return false; }
}

Try / catch

try {
    Object v = wrapper.getPropertyValue(propertyName);
} catch (InvalidPropertyException ex) {
    Throwable cause = ex.getCause(); // InvocationTargetException target
    // handle or rethrow as domain error
}

Prevention

When it happens

Trigger: A getter that dereferences a null internal field (NullPointerException), performs an illegal computation, or enforces a precondition that fails; a getter in a proxy/Lazy bean that fails on access; read-only computed properties whose backing data is missing.

Common situations: Bugs inside getter logic; Lombok-generated getters over uninitialized fields; Hibernate/proxy entity getters accessed outside a session; defensive getters that throw on invalid state.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/e5aa935b3d0dc276.json. Report an issue: GitHub.