{"record":{"id":"f3e2cd7a2494822d","repo":"stanfordnlp/CoreNLP","slug":"error-getting-field-value-for-fieldname","errorCode":null,"errorMessage":"Error getting field value for {fieldName}","messagePattern":"Error getting field value for (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/statistical/StatisticalCorefTrainer.java","lineNumber":72,"sourceCode":"    makeDir(extractedFeaturesPath);\n\n    datasetFile = dataPath + \"dataset.ser\";\n    predictionsName = name + \"_predictions\";\n    goldClustersFile = dataPath + \"gold_clusters.ser\";\n    mentionTypesFile = dataPath + \"mention_types.ser\";\n    compressorFile = extractedFeaturesPath + \"compressor.ser\";\n    extractedFeaturesFile = extractedFeaturesPath + \"compressed_features.ser\";\n  }\n\n  public static String fieldValues(Object o) {\n    String s = \"\";\n    Field[] fields = o.getClass().getDeclaredFields();\n    for (Field field : fields) {\n      try {\n        field.setAccessible(true);\n        s += field.getName() + \" = \" + field.get(o) + \"\\n\";\n      } catch (Exception e) {\n        throw new RuntimeException(\"Error getting field value for \" + field.getName(), e);\n      }\n    }\n    return s;\n  }\n\n  private static void preprocess(Properties props, Dictionaries dictionaries, boolean isTrainSet)\n      throws Exception {\n    (isTrainSet ? new DatasetBuilder(StatisticalCorefProperties.minClassImbalance(props),\n        StatisticalCorefProperties.maxTrainExamplesPerDocument(props)) :\n          new DatasetBuilder()).runFromScratch(props, dictionaries);\n    new MetadataWriter(isTrainSet).runFromScratch(props, dictionaries);\n    new FeatureExtractorRunner(props, dictionaries).runFromScratch(props, dictionaries);\n  }\n\n  public static void doTraining(Properties props) throws Exception {\n    setTrainingPath(props);\n    Dictionaries dictionaries = new Dictionaries(props);\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/statistical/StatisticalCorefTrainer.java#L54-L90","documentation":"The debug helper fieldValues uses reflection (field.get(o)) to dump all declared fields of an object; any reflective access failure (IllegalAccessException, IllegalArgumentException, etc.) is wrapped in a RuntimeException with this message naming the field.","triggerScenarios":"Calling fieldValues(o) when a declared field of o's class cannot be accessed reflectively — e.g. security manager/JPMS denies setAccessible, or the field belongs to a different class instance for primitives/primitive wrappers edge cases.","commonSituations":"Running CoreNLP training/debug on JDK 9+ with strong encapsulation where setAccessible on JDK-internal or private fields fails; custom classloaders; SecurityManager restrictions.","solutions":["Run with --add-opens flags for the failing package, or downgrade expectations and use toString() instead of reflection","Remove SecurityManager / module access restrictions for the code doing reflection","Only call fieldValues on CoreNLP's own model/config classes, not JDK or third-party objects"],"exampleFix":"// before\njava --module-path corenlp.jar ...  // JDK 17, setAccessible fails\n// after\njava --add-opens edu.stanford.nlp.coref.statistical=ALL-UNNAMED --module-path corenlp.jar ...","handlingStrategy":"validation","validationCode":"if (System.getSecurityManager() != null)\n  throw new IllegalStateException(\"fieldValues reflection requires no SecurityManager\");","typeGuard":null,"tryCatchPattern":"try {\n  String dump = fieldValues(o);\n} catch (RuntimeException e) {\n  logger.warning(\"reflective dump failed: \" + e.getMessage());\n  String dump = o.toString();\n}","preventionTips":["On JDK 9+, add --add-opens for packages whose private fields must be read","Only call fieldValues on CoreNLP's own classes","Avoid SecurityManager in training environments"],"tags":["reflection","java","accessibility","debugging"],"backgroundTag":"insufficient-permissions","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"}