{"record":{"id":"8ac207edbfc16b44","repo":"spring-projects/spring-framework","slug":"invalid-property-field-getname-of-bean-class","errorCode":null,"errorMessage":"Invalid property '{field.getName()}' of bean class [{beanClass.getName()}]: Field is not accessible","messagePattern":"Invalid property '(.+?)' of bean class \\[(.+?)\\]: Field is not accessible","errorType":"exception","errorClass":"InvalidPropertyException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java","lineNumber":147,"sourceCode":"\t\t@Override\n\t\tpublic TypeDescriptor getCollectionType(int nestingLevel) {\n\t\t\treturn new TypeDescriptor(this.resolvableType.getNested(nestingLevel).asCollection().getGeneric(),\n\t\t\t\t\tnull, this.field.getAnnotations());\n\t\t}\n\n\t\t@Override\n\t\tpublic @Nullable TypeDescriptor nested(int level) {\n\t\t\treturn TypeDescriptor.nested(this.field, level);\n\t\t}\n\n\t\t@Override\n\t\tpublic @Nullable Object getValue() throws Exception {\n\t\t\ttry {\n\t\t\t\tReflectionUtils.makeAccessible(this.field);\n\t\t\t\treturn this.field.get(getWrappedInstance());\n\t\t\t}\n\t\t\tcatch (IllegalAccessException | InaccessibleObjectException ex) {\n\t\t\t\tthrow new InvalidPropertyException(getWrappedClass(),\n\t\t\t\t\t\tthis.field.getName(), \"Field is not accessible\", ex);\n\t\t\t}\n\t\t}\n\n\t\t@Override\n\t\tpublic void setValue(@Nullable Object value) throws Exception {\n\t\t\ttry {\n\t\t\t\tReflectionUtils.makeAccessible(this.field);\n\t\t\t\tthis.field.set(getWrappedInstance(), value);\n\t\t\t}\n\t\t\tcatch (IllegalAccessException | InaccessibleObjectException ex) {\n\t\t\t\tthrow new InvalidPropertyException(getWrappedClass(), this.field.getName(),\n\t\t\t\t\t\t\"Field is not accessible\", ex);\n\t\t\t}\n\t\t}\n\t}\n\n}","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java#L129-L165","documentation":"Thrown as InvalidPropertyException by DirectFieldAccessor.FieldPropertyHandler.getValue when field.get(wrappedInstance) raises IllegalAccessException or java.lang.reflect.InaccessibleObjectException, even after ReflectionUtils.makeAccessible. Indicates the JVM refuses reflective read access to the field.","triggerScenarios":"DirectFieldAccessor reads a field via reflection; if the field belongs to a class in another module that has not been opened to Spring, makeAccessible/setAccessible throws InaccessibleObjectException, which is caught and rethrown as InvalidPropertyException 'Field is not accessible'.","commonSituations":"Running on JDK 16+ where strong encapsulation is enforced by default, accessing a field of a JDK class or a third-party module that has not opened its package to the application, or a SecurityManager denying access.","solutions":["Add --add-opens=<module>/<package>=ALL-UNNAMED (or =spring.beans) to the JVM args for the offending module/package.","Ensure the field is on a class you control and is at least package/private accessible from a location Spring can reach; prefer public fields for cross-module access.","If you cannot open the module, switch to a BeanWrapper that uses public getters/setters instead of field access."],"exampleFix":"// before: java --add-opens absent, DirectFieldAccessor reads a JDK-class field\nDirectFieldAccessor accessor = new DirectFieldAccessor(jdkInternal);\naccessor.getPropertyValue(\"field\");\n\n// after: launch with\n// java --add-opens=java.base/java.lang=ALL-UNNAMED ...","handlingStrategy":"try-catch","validationCode":"// preflight: can we reflectively read the field?\ntry {\n    ReflectionUtils.makeAccessible(field);\n    field.get(bean);\n} catch (IllegalAccessException | InaccessibleObjectException ex) {\n    // need --add-opens or different access strategy\n}","typeGuard":"static boolean fieldReadable(Field f, Object owner) {\n    try { ReflectionUtils.makeAccessible(f); f.get(owner); return true; }\n    catch (IllegalAccessException | InaccessibleObjectException e) { return false; }\n}","tryCatchPattern":"try {\n    accessor.getPropertyValue(name);\n} catch (InvalidPropertyException ex) {\n    if (ex.getMessage().contains(\"not accessible\")) {\n        // add --add-opens to JVM, or switch to BeanWrapper with public getters\n    }\n}","preventionTips":["On JDK 16+, document the required --add-opens in your run scripts.","Prefer public getters over field access for cross-module classes.","Test reflective field access in a unit test under the same JVM args as production."],"tags":["direct-field-accessor","jigsaw","jdk16","reflection","spring-beans"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}