{"record":{"id":"7b3e96b984a80652","repo":"spring-projects/spring-framework","slug":"invalid-property-propertyname-of-bean-class-7b3e96","errorCode":null,"errorMessage":"Invalid property '{propertyName}' of bean class [{beanClass.getName()}]: Getter for property '{actualName}' threw exception","messagePattern":"Invalid property '(.+?)' of bean class \\[(.+?)\\]: 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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L677-L713","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect getCause() of the InvalidPropertyException to find the real exception from the getter and fix that root cause.","Make the getter null-safe / defensive so it does not throw during property access.","Ensure required collaborators/state are set before the property is accessed (initialize dependencies first).","Avoid heavy or side-effecting logic inside getters used by BeanWrapper; move it to a service method."],"exampleFix":"// before\npublic Address getAddress() {\n  return address.getStreet().length(); // NPE if address null\n}\n\n// after\npublic Address getAddress() {\n  return address; // plain accessor; logic moved out","handlingStrategy":"try-catch","validationCode":"BeanWrapper w = new BeanWrapperImpl(bean);\n// best-effort: ensure dependencies the getter needs are set first\n// (no static guarantee a getter won't throw; keep getters simple)\nif (!w.isReadableProperty(\"x\")) return null;\nreturn w.getPropertyValue(\"x\");","typeGuard":null,"tryCatchPattern":"try {\n    return wrapper.getPropertyValue(\"x\");\n} catch (InvalidPropertyException ex) {\n    Throwable cause = ex.getCause() != null ? ex.getCause().getCause() : null;\n    // log cause; decide whether to treat as absent value or rethrow\n    if (cause instanceof IllegalStateException) return null;\n    throw ex;\n}","preventionTips":["Keep getters trivial accessors; move computed/throwing logic into service methods.","Inspect getCause() of InvalidPropertyException to find the real getter failure.","Initialize all collaborators/state before getters are invoked during binding.","Add unit tests that exercise getters on freshly constructed beans."],"tags":["spring-beans","bean-wrapper","getter","invocation-target","read"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}