{"record":{"id":"9ef96cdede0edc8a","repo":"Anuken/Mindustry","slug":"error-accessing-field-field-getname-type","errorCode":null,"errorMessage":"Error accessing field: ${field.getName()} (${type.getName()})","messagePattern":"Error accessing field: (.+?) \\((.+?)\\)","errorType":"exception","errorClass":"SerializationException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/mod/ContentParser.java","lineNumber":1325,"sourceCode":"\n                    Object readField = parser.readValue(field.getType(), metadata.elementType, child, metadata.keyType);\n                    Object fieldObj = field.get(object);\n\n                    //if a map has add: true, add its contents to the map instead\n                    if(mergeMap && (fieldObj instanceof ObjectMap<?,?> || fieldObj instanceof ObjectIntMap<?> || fieldObj instanceof ObjectFloatMap<?>)){\n                        if(field.get(object) instanceof ObjectMap<?,?> baseMap){\n                            baseMap.putAll((ObjectMap)readField);\n                        }else if(field.get(object) instanceof ObjectIntMap<?> baseMap){\n                            baseMap.putAll((ObjectIntMap)readField);\n                        }else if(field.get(object) instanceof ObjectFloatMap<?> baseMap){\n                            baseMap.putAll((ObjectFloatMap)readField);\n                        }\n                    }else{\n                        field.set(object, readField);\n                    }\n                }\n            }catch(IllegalAccessException ex){\n                throw new SerializationException(\"Error accessing field: \" + field.getName() + \" (\" + type.getName() + \")\", ex);\n            }catch(SerializationException ex){\n                ex.addTrace(field.getName() + \" (\" + type.getName() + \")\");\n                throw ex;\n            }catch(RuntimeException runtimeEx){\n                SerializationException ex = new SerializationException(runtimeEx);\n                ex.addTrace(child.trace());\n                ex.addTrace(field.getName() + \" (\" + type.getName() + \")\");\n                throw ex;\n            }\n        }\n\n        if(object instanceof UnlockableContent unlock && research != null){\n            if(!allowPatching){\n                warn(\"Modifying the tech tree is not allowed (@)\", currentFile);\n                return;\n            }\n\n            //add research tech node","sourceCodeStart":1307,"sourceCodeEnd":1343,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/mod/ContentParser.java#L1307-L1343","documentation":"While reflectively writing a parsed value into a field, an IllegalAccessException (or a conversion RuntimeException / nested SerializationException) is wrapped with the offending field and type. The trace is annotated with the field name and declaring class so the failing assignment can be located.","triggerScenarios":"Reflective field.set / field.get fails: final field that cannot be written, inaccessible member, or a value whose runtime type is incompatible with the field type so the conversion throws.","commonSituations":"Mod supplies a value of the wrong type for a field (e.g. string for an int, object for an enum); field type mismatch after a game update renamed/retyped a field; security/access edge cases on certain JVMs.","solutions":["Read the trace: 'field NAME (type)' identifies the failing assignment and its cause.","Correct the JSON value type to match the declared field type.","If the field is an enum, supply a valid enum constant name.","For map-type fields, confirm you are providing a JSON object, not a list."],"exampleFix":"// before\n\"category\": 3\n// error accessing field: category (mindustry.world.meta.Category)\n\n// after\n\"category\": \"turret\"","handlingStrategy":"try-catch","validationCode":"// Validate a JSON value matches a field's expected type before assignment where feasible.\nFieldMetadata meta = fields.get(childName.replace(\" \", \"_\"));\nif(meta == null && !ignoreUnknownFields) throw new SerializationException(\"Unknown field: \" + childName);","typeGuard":null,"tryCatchPattern":"try {\n    parser.readFields(obj, jsonMap);\n} catch(SerializationException e) {\n    // e.getMessage() starts with 'Error accessing field'; e.getCause() holds the real reason\n    log.error(\"Field parse failed: {}\", e.getMessage(), e);\n}","preventionTips":["Match JSON value types to declared field types exactly.","Use correct enum constant names.","Avoid relying on reflective writes to final fields."],"tags":["modding","content-parsing","reflection","serialization"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}