{"record":{"id":"c426df80a67cc359","repo":"ssssssss-team/spider-flow","slug":"couldn-t-get-value-of-field-javafield-getname","errorCode":null,"errorMessage":"Couldn't get value of field '\" + javaField.getName() + \"' from object of type '\" + obj.getClass().getSimpleName() + \"'","messagePattern":"Couldn't get value of field '\" \\+ javaField\\.getName\\(\\) \\+ \"' from object of type '\" \\+ obj\\.getClass\\(\\)\\.getSimpleName\\(\\) \\+ \"'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spider-flow-core/src/main/java/org/spiderflow/core/expression/interpreter/JavaReflection.java","lineNumber":63,"sourceCode":"\t\t\t\t\t\tfields.put(name, field);\n\t\t\t\t\t} catch (NoSuchFieldException e) {\n\t\t\t\t\t\t// fall through\n\t\t\t\t\t}\n\t\t\t\t\tparentClass = parentClass.getSuperclass();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn field;\n\t}\n\n\t@Override\n\tpublic Object getFieldValue (Object obj, Object field) {\n\t\tField javaField = (Field)field;\n\t\ttry {\n\t\t\treturn javaField.get(obj);\n\t\t} catch (Throwable e) {\n\t\t\tthrow new RuntimeException(\"Couldn't get value of field '\" + javaField.getName() + \"' from object of type '\" + obj.getClass().getSimpleName() + \"'\");\n\t\t}\n\t}\n\t\n\t@Override\n\tpublic void registerExtensionClass(Class<?> target,Class<?> clazz){\n\t\tMethod[] methods = clazz.getDeclaredMethods();\n\t\tif(methods != null){\n\t\t\tMap<String, List<Method>> cachedMethodMap = extensionmethodCache.get(target);\n\t\t\tif(cachedMethodMap == null){\n\t\t\t\tcachedMethodMap = new HashMap<>();\n\t\t\t\textensionmethodCache.put(target,cachedMethodMap);\n\t\t\t}\n\t\t\tfor (Method method : methods) {\n\t\t\t\tif(Modifier.isStatic(method.getModifiers()) && method.getParameterCount() > 0){\n\t\t\t\t\tList<Method> cachedList = cachedMethodMap.get(method.getName());\n\t\t\t\t\tif(cachedList == null){\n\t\t\t\t\t\tcachedList = new ArrayList<>();\n\t\t\t\t\t\tcachedMethodMap.put(method.getName(), cachedList);","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/ssssssss-team/spider-flow/blob/c799cca99c7d064673dc79e6ef06a08bbc0e292d/spider-flow-core/src/main/java/org/spiderflow/core/expression/interpreter/JavaReflection.java#L45-L81","documentation":"JavaReflection.getFieldValue retrieves a reflective Field's value from an object via Field.get(obj). If the reflective access throws for any reason (illegal access, mismatched object, initializer failure), it wraps it in a RuntimeException naming the field and the object's simple class name.","triggerScenarios":"Calling getFieldValue(obj, field) where the Field is inaccessible (non-public without setAccessible), obj is not an instance of the declaring class, or the field's class fails to initialize.","commonSituations":"Expression evaluation accessing object properties on beans with private fields; passing an object of the wrong type; JDK module system blocking reflective access (Java 9+).","solutions":["Ensure the object passed is an instance of the field's declaring class","Make the field public or call setAccessible(true) on the Field before access","Add JVM args --add-opens for the relevant package when running on Java 9+","Catch the RuntimeException at the evaluation call site and log field name plus cause"],"exampleFix":"// before\nObject v = reflection.getFieldValue(obj, field);\n// after\nField f = (Field) field;\nf.setAccessible(true);\nif (!f.getDeclaringClass().isInstance(obj)) {\n    throw new IllegalArgumentException(obj + \" is not a \" + f.getDeclaringClass());\n}\nObject v = reflection.getFieldValue(obj, field);","handlingStrategy":"try-catch","validationCode":"if (obj == null || !((Field) field).getDeclaringClass().isInstance(obj)) {\n    throw new IllegalArgumentException(\"Object not compatible with field \" + field);\n}","typeGuard":"boolean canRead(Object obj, Field f) {\n    return obj != null && f.getDeclaringClass().isInstance(obj);\n}","tryCatchPattern":"try {\n    Object v = reflection.getFieldValue(obj, field);\n} catch (RuntimeException e) {\n    logger.error(\"Field access failed: {}\", e.getMessage(), e.getCause());\n    throw new ExpressionEvaluationException(\"Cannot read field\", e);\n}","preventionTips":["Prefer getters over direct field reflection for non-public fields","Call setAccessible(true) when accessing non-public fields intentionally","Run on JVM versions/modules that permit the required --add-opens","Validate object types before reflective access"],"tags":["reflection","java","field-access"],"backgroundTag":"reflection-access-failed","analyzedSha":"c799cca99c7d064673dc79e6ef06a08bbc0e292d","analyzedAt":"2026-09-08T13:47:08.225Z","contentChangedAt":"2026-09-08T13:47:08.225Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}