Anuken/Mindustry · error · SerializationException

Error accessing field: ${field.getName()} (${type.getName()}

Error message

Error accessing field: ${field.getName()} (${type.getName()})

What it means

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.

Source

Thrown at core/src/mindustry/mod/ContentParser.java:1325

                    Object readField = parser.readValue(field.getType(), metadata.elementType, child, metadata.keyType);
                    Object fieldObj = field.get(object);

                    //if a map has add: true, add its contents to the map instead
                    if(mergeMap && (fieldObj instanceof ObjectMap<?,?> || fieldObj instanceof ObjectIntMap<?> || fieldObj instanceof ObjectFloatMap<?>)){
                        if(field.get(object) instanceof ObjectMap<?,?> baseMap){
                            baseMap.putAll((ObjectMap)readField);
                        }else if(field.get(object) instanceof ObjectIntMap<?> baseMap){
                            baseMap.putAll((ObjectIntMap)readField);
                        }else if(field.get(object) instanceof ObjectFloatMap<?> baseMap){
                            baseMap.putAll((ObjectFloatMap)readField);
                        }
                    }else{
                        field.set(object, readField);
                    }
                }
            }catch(IllegalAccessException ex){
                throw new SerializationException("Error accessing field: " + field.getName() + " (" + type.getName() + ")", ex);
            }catch(SerializationException ex){
                ex.addTrace(field.getName() + " (" + type.getName() + ")");
                throw ex;
            }catch(RuntimeException runtimeEx){
                SerializationException ex = new SerializationException(runtimeEx);
                ex.addTrace(child.trace());
                ex.addTrace(field.getName() + " (" + type.getName() + ")");
                throw ex;
            }
        }

        if(object instanceof UnlockableContent unlock && research != null){
            if(!allowPatching){
                warn("Modifying the tech tree is not allowed (@)", currentFile);
                return;
            }

            //add research tech node

View on GitHub (pinned to f695ad7e60)

Solutions

  1. Read the trace: 'field NAME (type)' identifies the failing assignment and its cause.
  2. Correct the JSON value type to match the declared field type.
  3. If the field is an enum, supply a valid enum constant name.
  4. For map-type fields, confirm you are providing a JSON object, not a list.

Example fix

// before
"category": 3
// error accessing field: category (mindustry.world.meta.Category)

// after
"category": "turret"
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate a JSON value matches a field's expected type before assignment where feasible.
FieldMetadata meta = fields.get(childName.replace(" ", "_"));
if(meta == null && !ignoreUnknownFields) throw new SerializationException("Unknown field: " + childName);

Try / catch

try {
    parser.readFields(obj, jsonMap);
} catch(SerializationException e) {
    // e.getMessage() starts with 'Error accessing field'; e.getCause() holds the real reason
    log.error("Field parse failed: {}", e.getMessage(), e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Anuken/Mindustry@f695ad7e60 (2026-08-14). Data as JSON: /api/errors/9ef96cdede0edc8a. Report an issue: GitHub.