{"id":"e5aa935b3d0dc276","repo":"spring-projects/spring-framework","slug":"getter-for-property-actualname-threw-exceptio","errorCode":null,"errorMessage":"Getter for property '${actualName}' threw exception","messagePattern":"Getter for property '(.+?)' threw exception","errorType":"exception","errorClass":"InvalidPropertyException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":695,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\tindexedPropertyName.append(PROPERTY_KEY_PREFIX).append(key).append(PROPERTY_KEY_SUFFIX);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcatch (InvalidPropertyException ex) {\n\t\t\tthrow ex;\n\t\t}\n\t\tcatch (IndexOutOfBoundsException ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Index of out of bounds in property path '\" + propertyName + \"'\", ex);\n\t\t}\n\t\tcatch (NumberFormatException | TypeMismatchException ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Invalid index in property path '\" + propertyName + \"'\", ex);\n\t\t}\n\t\tcatch (InvocationTargetException ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Getter for property '\" + actualName + \"' threw exception\", ex);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Illegal attempt to get property '\" + actualName + \"' threw exception\", ex);\n\t\t}\n\t}\n\n\n\t/**\n\t * Return the {@link PropertyHandler} for the specified {@code propertyName}, navigating\n\t * if necessary. Return {@code null} if not found rather than throwing an exception.\n\t * @param propertyName the property to obtain the descriptor for\n\t * @return the property descriptor for the specified property,\n\t * or {@code null} if not found\n\t * @throws BeansException in case of introspection failure\n\t */\n\tprotected @Nullable PropertyHandler getPropertyHandler(String propertyName) throws BeansException {","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L677-L713","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the wrapped exception cause to find which getter line threw and fix that code path.","Ensure the bean's internal state is fully initialized before the property is read.","Guard the getter itself against null/invalid state rather than throwing.","If accessing a lazy/proxy entity, make sure the owning session/context is open."],"exampleFix":"// before\npublic String getCity() { return address.getCity(); } // NPE if address == null\n\n// after\npublic String getCity() { return address != null ? address.getCity() : null; }","handlingStrategy":"try-catch","validationCode":"// Ensure bean state is fully initialized before reading:\nif (bean.getAddress() != null) {\n    wrapper.getPropertyValue(\"address.city\");\n}","typeGuard":"static boolean getterIsSafe(Object bean, String getter) {\n    try { bean.getClass().getMethod(getter).invoke(bean); return true; }\n    catch (Exception ex) { return false; }\n}","tryCatchPattern":"try {\n    Object v = wrapper.getPropertyValue(propertyName);\n} catch (InvalidPropertyException ex) {\n    Throwable cause = ex.getCause(); // InvocationTargetException target\n    // handle or rethrow as domain error\n}","preventionTips":["Initialize all fields a getter dereferences.","Make getters null-safe rather than throwing.","Keep lazy/proxy entities within an active session/context when read."],"tags":["spring-beans","bean-wrapper","getter","invocation-target","runtime-exception"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}