{"record":{"id":"8fff527aa559a7cd","repo":"MyCATApache/Mycat-Server","slug":"no-such-field-classname-fieldname","errorCode":null,"errorMessage":"No such field ${className}.${fieldName}","messagePattern":"No such field (.+?)\\.(.+?)","errorType":"exception","errorClass":"ObjectAccessException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/util/FieldDictionary.java","lineNumber":73,"sourceCode":"     * for the field named 'name' inside the class cls. If definedIn is\n     * different than null, tries to find the specified field name in the\n     * specified class cls which should be defined in class definedIn (either\n     * equals cls or a one of it's superclasses)\n     * \n     * @param cls\n     *            the class where the field is to be searched\n     * @param name\n     *            the field name\n     * @param definedIn\n     *            the superclass (or the class itself) of cls where the field\n     *            was defined\n     * @return the field itself\n     */\n    public Field field(Class<?> cls, String name, Class<?> definedIn) {\n        Map<?, Field> fields = buildMap(cls, definedIn != null);\n        Field field = fields.get(definedIn != null ? new FieldKey(name, definedIn, 0) : name);\n        if (field == null) {\n            throw new ObjectAccessException(\"No such field \" + cls.getName() + \".\" + name);\n        } else {\n            return field;\n        }\n    }\n\n    private Map<?, Field> buildMap(Class<?> cls, boolean tupleKeyed) {\n        final String clsName = cls.getName();\n        if (!nameCache.containsKey(clsName)) {\n            synchronized (keyCache) {\n                if (!nameCache.containsKey(clsName)) { // double check\n                    final Map<String, Field> keyedByFieldName = new HashMap<String, Field>();\n                    final Map<FieldKey, Field> keyedByFieldKey = new OrderRetainingMap<FieldKey, Field>();\n                    while (!Object.class.equals(cls)) {\n                        Field[] fields = cls.getDeclaredFields();\n                        if (JVMInfo.reverseFieldDefinition()) {\n                            for (int i = fields.length >> 1; i-- > 0;) {\n                                final int idx = fields.length - i - 1;\n                                final Field field = fields[i];","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/util/FieldDictionary.java#L55-L91","documentation":"FieldDictionary.field looks up a Field by name (and optionally declaring class) via reflection and throws ObjectAccessException when no matching field exists on the class. This is XStream-style reflection machinery used during object (de)serialization of config beans.","triggerScenarios":"Calling field(cls, name) or field(cls, name, definedIn) with a field name that does not exist on cls or any of its superclasses up to definedIn; typically during XML unmarshalling when an XML element/attribute name has no corresponding Java field.","commonSituations":"XML config contains an element/attribute renamed or misspelled relative to the Java bean; class was refactored (field renamed/removed) while old XML files still reference the old name; version mismatch between config files and library classes.","solutions":["Correct the field/element name in the XML to match an actual field on the class","Add the missing field to the target class (or a @XStreamAlias-style mapping) if the XML format is canonical","Check for version skew: regenerate old config files to match the current class definitions"],"exampleFix":"<!-- before: class User has no field 'userName' -->\n<user><userName>bob</userName></user>\n<!-- after -->\n<user><name>bob</name></user>","handlingStrategy":"try-catch","validationCode":"boolean has = false;\nfor (Class<?> c = cls; c != null; c = c.getSuperclass()) {\n  try { c.getDeclaredField(name); has = true; break; } catch (NoSuchFieldException ignored) {}\n}\nif (!has) throw new IllegalArgumentException(\"no field \" + cls.getName() + \".\" + name);","typeGuard":null,"tryCatchPattern":"try { return dictionary.field(cls, name); } catch (ObjectAccessException e) { log.warn(\"field {} missing on {}, using default\", name, cls.getName()); return null; }","preventionTips":["Keep XML element/attribute names in sync with bean field names (aliases)","After renaming fields, grep config files for the old name","Pin config-file format to the library version and migrate on upgrade"],"tags":["reflection","serialization","field-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}