{"record":{"id":"68cbf5a2c38e2300","repo":"stanfordnlp/CoreNLP","slug":"cannot-get-field-fieldname-from-v","errorCode":null,"errorMessage":"Cannot get field ${fieldName} from ${v}","messagePattern":"Cannot get field (.+?) from (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java","lineNumber":1345,"sourceCode":"                    if (elem instanceof Value) {\n                      list2.add(((Value) elem).get());\n                    } else {\n                      list2.add(elem);\n                    }\n                  }\n                  f.set(obj, list2);\n                }\n              } else {\n                f.set(obj, Arrays.asList(fieldValue.get()));\n              }\n            } else {\n              f.set(obj, fieldValue.get());\n            }\n          }\n        }\n        return Expressions.createValue(null, f.get(obj));\n      } catch (NoSuchFieldException | IllegalAccessException ex) {\n        throw new RuntimeException(\"Cannot get field \" + fieldName + \" from \" + v, ex);\n      }\n    }\n  };\n\n  public static final ValueFunction LIST_VALUE_FUNCTION = new NamedValueFunction(\"LIST_VALUE\") {\n    @Override\n    public String getParamDesc() {\n      return \"List list,int index,[Object value]\";\n    }\n\n    // First argument is List\n    // Second argument is index of element to select\n    // Third argument (optional) is value to assign list element\n    @Override\n    public boolean checkArgs(List<Value> in) {\n      if (in.size() != 2 && in.size() != 3) {\n        return false;\n      }","sourceCodeStart":1327,"sourceCodeEnd":1363,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ling/tokensregex/types/ValueFunctions.java#L1327-L1363","documentation":"Thrown when the FIELD value function cannot read the requested field from an object via reflection; the underlying NoSuchFieldException or IllegalAccessException is wrapped in a RuntimeException. It means the field name in the expression does not exist on (or is not accessible from) the target object's class.","triggerScenarios":"Evaluating a TokensRegex expression using FIELD(obj, \"fieldName\") where fieldName is misspelled or absent from the object's class, or the field is inaccessible (not public, wrong classloader).","commonSituations":"Typo'd field names in TokensRegex custom expressions; referencing fields of private classes or after refactoring renamed fields; accessing fields of wrapper/boxed objects mistakenly assumed to be the domain object.","solutions":["Verify the field name against the target class (or add the field).","Make the field public, or access it via a public getter through a supported function instead of FIELD.","Catch RuntimeException around expression evaluation and fall back to a null/typed value."],"exampleFix":"// before\nValue v = FIELD($obj, \"sentance\");  // misspelled\n// after\nValue v = FIELD($obj, \"sentence\");","handlingStrategy":"try-catch","validationCode":"try { Class.forName(obj.getClass().getName(), false, cl).getField(fieldName); } catch (NoSuchFieldException e) { /* invalid field name */ }","typeGuard":"boolean hasField(Object o, String name) { try { o.getClass().getField(name); return true; } catch (NoSuchFieldException e) { return false; } }","tryCatchPattern":"try { Value v = FIELD($obj, fieldName); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot get field \")) { v = Expressions.createValue(null, null); } else throw e; }","preventionTips":["Keep field names in constants shared with the domain class","Make reflected fields public or expose getters","Re-run expression tests after renaming class fields"],"tags":["reflection","tokensregex","java"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}