Anuken/Mindustry · error · SerializationException

Integer bitfield values must all be strings. Found: ${str}

Error message

Integer bitfield values must all be strings. Found: ${str}

What it means

Thrown when parsing an int/Integer field supplied as a JSON array (env bitfield syntax): every element must be a string naming a field on the Env class. A non-string element is rejected before Reflect.get is attempted.

Source

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

        private <T> T internalRead(Class<T> type, Class elementType, JsonValue jsonData, Class keyType){
            if(type != null){
                if(classParsers.containsKey(type)){
                    try{
                        return (T)classParsers.get(type).parse(type, jsonData);
                    }catch(Exception e){
                        if(e instanceof RuntimeException rt){
                            throw rt;
                        }
                        throw new RuntimeException(e);
                    }
                }

                //try to parse env bits
                if((type == int.class || type == Integer.class) && jsonData.isArray()){
                    int value = 0;
                    for(var str : jsonData){
                        if(!str.isString()) throw new SerializationException("Integer bitfield values must all be strings. Found: " + str);
                        String field = str.asString();
                        value |= Reflect.<Integer>get(Env.class, field);
                    }

                    return (T)(Integer)value;
                }

                //try to parse "item/amount" syntax
                if(type == ItemStack.class && jsonData.isString() && jsonData.asString().contains("/")){
                    String[] split = jsonData.asString().split("/");

                    return (T)fromJson(ItemStack.class, "{item: " + split[0] + ", amount: " + split[1] + "}");
                }

                //try to parse "payloaditem/amount" syntax
                if(type == PayloadStack.class && jsonData.isString() && jsonData.asString().contains("/")){
                    String[] split = jsonData.asString().split("/");
                    int number = Strings.parseInt(split[1], 1);

View on GitHub (pinned to f695ad7e60)

Solutions

  1. Use string Env field names as array elements.
  2. Verify each name corresponds to a public field on mindustry.game.Env.

Example fix

// before
"env": [1, 2]
// after
"env": ["space", "ground"]
Defensive patterns

Strategy: type-guard

Type guard

// Guard: every element of an int bitfield array must be a string Env field name.
boolean validBitfield(JsonValue arr) {
    if (!arr.isArray()) return false;
    for (var e : arr) if (!e.isString()) return false;
    return true;
}

Prevention

When it happens

Trigger: A mod JSON provides an integer/bitfield field (e.g. `env`) as an array containing numbers or objects instead of Env field-name strings.

Common situations: Writing `env: [1, 2]` instead of `env: ["space", "ground"]`, or copying numeric bit values from documentation.

Related errors


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