Anuken/Mindustry · error · IllegalArgumentException

${type.getSimpleName()}: not found: '${name}'

Error message

${type.getSimpleName()}: not found: '${name}'

What it means

field(Class, name) reads a static field by reflection via type.getField(name).get(null). If the field is absent or resolves to null, it throws IllegalArgumentException with the class and field name. Note: because the catch(Exception) wraps NoSuchFieldException too, the message ('not found') can be emitted either by the explicit null check or by the wrapped reflection exception.

Source

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

            throw new RuntimeException(e);
        }
    }

    Prov<UnitController> resolveController(String type){
        //this is used as a captured value to avoid parsing it multiple times
        var controller = supply(resolve(type, FlyingAI.class));
        return controller::get;
    }

    Object field(Class<?> type, JsonValue value){
        return field(type, value.asString());
    }

    /** Gets a field from a static class by name, throwing a descriptive exception if not found. */
    private Object field(Class<?> type, String name){
        try{
            Object b = type.getField(name).get(null);
            if(b == null) throw new IllegalArgumentException(type.getSimpleName() + ": not found: '" + name + "'");
            return b;
        }catch(Exception e){
            throw new RuntimeException(e);
        }
    }
    Object fieldOpt(Class<?> type, JsonValue value){
        try{
            return type.getField(value.asString()).get(null);
        }catch(Exception e){
            return null;
        }
    }

    void checkNullFields(Object object){
        if(object == null || object instanceof Number || object instanceof String || toBeParsed.contains(object) || object.getClass().getName().startsWith("arc.")) return;

        parser.getFields(object.getClass()).values().toSeq().each(field -> {
            try{

View on GitHub (pinned to f695ad7e60)

Solutions

  1. Verify the field name is a public static member of the target class.
  2. Correct typos against the class's source.
  3. Ensure the field is non-null at parse time.

Example fix

// before
field(Items.class, "coper")
// after
field(Items.class, "copper")
Defensive patterns

Strategy: try-catch

Validate before calling

// Check the static field exists and is non-null before reading.
try {
    java.lang.reflect.Field f = type.getField(name);
    if(f.get(null) == null) throw new IllegalStateException(type.getSimpleName() + "." + name + " is null");
} catch(NoSuchFieldException e){
    throw new IllegalStateException(type.getSimpleName() + " has no field '" + name + "'");
}

Type guard

boolean hasStaticField(Class<?> type, String name){
    try { return type.getField(name).get(null) != null; }
    catch(Exception e){ return false; }
}

Try / catch

try { Object v = field(MyClass.class, "NAME"); }
catch(RuntimeException e){ /* field() wraps NoSuchFieldException; log and degrade */ Log.err(e); }

Prevention

When it happens

Trigger: A JSON reference names a static field that does not exist on the target class (e.g. an item/block/color constant), or exists but holds null.

Common situations: Referencing a color constant, item, or block by a name that isn't a public static field on the resolved class; typo; using a field from the wrong class.

Related errors


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