{"record":{"id":"05176b20c3e4fb1a","repo":"spring-projects/spring-framework","slug":"invalid-property-propertyname-of-bean-class-05176b","errorCode":null,"errorMessage":"Invalid property '{propertyName}' of bean class [{beanClass.getName()}]: Illegal attempt to get property '{actualName}' threw exception","messagePattern":"Invalid property '(.+?)' of bean class \\[(.+?)\\]: Illegal attempt to get property '(.+?)' threw exception","errorType":"exception","errorClass":"InvalidPropertyException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":699,"sourceCode":"\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 {\n\t\tAssert.notNull(propertyName, \"Property name must not be null\");\n\t\tAbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName);\n\t\treturn nestedPa.getLocalPropertyHandler(getFinalPath(nestedPa, propertyName));\n\t}","sourceCodeStart":681,"sourceCodeEnd":717,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L681-L717","documentation":"Thrown as an InvalidPropertyException when reading a property via a BeanWrapper/property accessor and the getter invocation throws an exception that is NOT already handled by a more specific catch (InvocationTargetException, NumberFormatException, TypeMismatchException, IndexOutOfBoundsException). It is the generic fallback in getPropertyValue(PropertyTokenHolder) at AbstractNestablePropertyAccessor.java:698-701, wrapping the original cause. The message literally accuses an 'Illegal attempt to get property'.","triggerScenarios":"Call getPropertyValue on a nested/indexed path whose underlying PropertyHandler.getValue() (the read method or field accessor) throws a RuntimeException such as IllegalStateException, IllegalArgumentException from inside the getter, an AOP/proxy failure, a NullPointerException surfaced from the getter body, or a privileged-action exception that is not an InvocationTargetException.","commonSituations":"Data binding onto a bean whose getter computes/derives a value and that computation fails (e.g. getSubtotal() divides by zero or dereferences a null); a CGLIB/proxied bean whose advice throws in the getter; SpEL/BeanWrapper property traversal where an intermediate getter relies on uninitialized state; reading a property on a Kotlin/record type whose accessor has side effects.","solutions":["Inspect the wrapped cause via getCause()/getRootCause() of the InvalidPropertyException to find the real exception thrown by the getter.","Reproduce by calling the bean's getter directly (bean.getXyz()) outside of the BeanWrapper to confirm the getter itself throws.","Fix the getter to not throw, or guard the upstream state so the property is read only when valid.","If reading through a proxy, ensure the target bean's method is public and the proxy/AOP advice is not failing."],"exampleFix":"// before: derived getter throws when inner list is null\npublic int getCount() { return items.size(); }\n\n// after: null-safe getter\npublic int getCount() { return items != null ? items.size() : 0; }","handlingStrategy":"try-catch","validationCode":"// Validate the getter is safe before traversal\nPropertyHandler check via reflection:\nPropertyDescriptor pd = BeanUtils.getPropertyDescriptor(bean.getClass(), \"x\");\nif (pd != null && pd.getReadMethod() != null\n        && wrapper.isReadableProperty(\"x\")) {\n    // safe-ish; still call inside try/catch\n}","typeGuard":"// Narrow to beans whose getter does not throw by sampling\nstatic boolean safeToRead(BeanWrapper w, String path) {\n    try { w.getPropertyValue(path); return true; }\n    catch (InvalidPropertyException ex) {\n        return !(ex.getCause() instanceof RuntimeException);\n    }\n}","tryCatchPattern":"try {\n    Object v = wrapper.getPropertyValue(nestedPath);\n} catch (InvalidPropertyException ex) {\n    Throwable root = ex.getCause(); // the real exception from the getter\n    // distinguish getter-failure (root != null) from genuine invalid path\n    log.warn(\"getter for {} threw\", nestedPath, root);\n}","preventionTips":["Make getters pure and null-safe; never do I/O or heavy computation in a getter used by BeanWrapper.","When binding to derived properties, mark them read-only in metadata or exclude them.","Unit-test getters independently before wiring through property access.","Inspect getCause() of any InvalidPropertyException to differentiate getter bugs from path typos."],"tags":["spring-beans","beanwrapper","property-access","reflection","getter"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}