{"record":{"id":"0619585b255f5c63","repo":"apache/iceberg","slug":"cannot-find-field-from-candidates-candidates","errorCode":null,"errorMessage":"Cannot find field from candidates: ${candidates}","messagePattern":"Cannot find field from candidates: (.+?)","errorType":"exception","errorClass":"NoSuchFieldException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/org/apache/iceberg/common/DynFields.java","lineNumber":385,"sourceCode":"      return this;\n    }\n\n    /**\n     * Returns the first valid implementation as a UnboundField or throws a NoSuchFieldException if\n     * there is none.\n     *\n     * @param <T> Java class stored in the field\n     * @return a {@link UnboundField} with a valid implementation\n     * @throws NoSuchFieldException if no implementation was found\n     */\n    @SuppressWarnings(\"unchecked\")\n    public <T> UnboundField<T> buildChecked() throws NoSuchFieldException {\n      if (field != null) {\n        return (UnboundField<T>) field;\n      } else if (defaultAlwaysNull) {\n        return (UnboundField<T>) AlwaysNull.INSTANCE;\n      } else {\n        throw new NoSuchFieldException(\n            \"Cannot find field from candidates: \" + Joiner.on(\", \").join(candidates));\n      }\n    }\n\n    /**\n     * Returns the first valid implementation as a BoundMethod or throws a NoSuchMethodException if\n     * there is none.\n     *\n     * @param target an Object on which to get and set the field\n     * @param <T> Java class stored in the field\n     * @return a {@link BoundField} with a valid implementation and target\n     * @throws IllegalStateException if the method is static\n     * @throws IllegalArgumentException if the receiver's class is incompatible\n     * @throws NoSuchFieldException if no implementation was found\n     */\n    public <T> BoundField<T> buildChecked(Object target) throws NoSuchFieldException {\n      return this.<T>buildChecked().bind(target);\n    }","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/common/src/main/java/org/apache/iceberg/common/DynFields.java#L367-L403","documentation":"DynFields.Builder.buildChecked() throws NoSuchFieldException when none of the candidate field names resolved to a real field and no default was configured. The message lists all candidate names that were tried. This is the checked variant that forces callers to handle lookup failure.","triggerScenarios":"DynFields.builder().hiddenImpl(\"a.C\", \"field\").buildChecked() where the target class has none of the candidate fields and defaultAlwaysNull is not set.","commonSituations":"Reflecting into internals that changed across library versions (field renamed/removed); typos in field names; accessing a field on the wrong class; accessing hidden fields in JDKs where reflection into non-exported packages is blocked.","solutions":["Check the candidate names against the actual runtime version of the target class; update them.","Use defaultImpl/AlwaysNull default when the field is optional, and handle the null value.","Ensure the declaring class is correct and the field's accessibility allows lookup (add --add-opens for JDK internals).","Prefer buildChecked() at startup so misconfiguration fails fast with the full candidate list."],"exampleFix":"// before\nUnboundField<String> f = DynFields.builder().hiddenImpl(\"Conf\", \"oldName\").buildChecked();\n// after\nUnboundField<String> f = DynFields.builder()\n    .hiddenImpl(\"Conf\", \"newName\")\n    .hiddenImpl(\"Conf\", \"oldName\")\n    .defaultAlwaysNull()\n    .buildChecked();","handlingStrategy":"try-catch","validationCode":"boolean fieldExists;\ntry {\n  TargetClass.class.getDeclaredField(\"fieldName\");\n  fieldExists = true;\n} catch (NoSuchFieldException e) {\n  fieldExists = false;\n}\nif (!fieldExists) { /* use alternative name or default */ }","typeGuard":null,"tryCatchPattern":"try {\n  UnboundField<T> f = DynFields.builder().hiddenImpl(Cls.class, \"name\").buildChecked();\n} catch (NoSuchFieldException e) {\n  // field missing in this runtime version: use fallback or fail with a clear message\n}","preventionTips":["Provide multiple candidate field names spanning supported library versions","Verify field names against the exact runtime version before deployment","Use defaultAlwaysNull() for optional fields and null-check at use sites","For JDK internals, add the required --add-opens flags to the JVM"],"tags":["reflection","fields","dependency"],"backgroundTag":"resource-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}