{"record":{"id":"536f9fc1912449e4","repo":"Anuken/Mindustry","slug":"name-is-null","errorCode":null,"errorMessage":"name is null","messagePattern":"name is null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/src/mindustry/tools/ImagePacker.java","lineNumber":293,"sourceCode":"        replace(((GenRegion)region).name, image);\n    }\n\n    static void err(String message, Object... args){\n        throw new IllegalArgumentException(Strings.format(message, args));\n    }\n\n    static void validate(TextureRegion region){\n        if(((GenRegion)region).invalid){\n            ImagePacker.err(\"Region does not exist: @\", ((GenRegion)region).name);\n        }\n    }\n\n    static class GenRegion extends AtlasRegion{\n        boolean invalid;\n        Fi path;\n\n        GenRegion(String name, Fi path){\n            if(name == null) throw new IllegalArgumentException(\"name is null\");\n            this.name = name;\n            this.path = path;\n        }\n\n        @Override\n        public boolean found(){\n            return !invalid;\n        }\n    }\n\n    static class PackIndex{\n        @Nullable AtlasRegion region;\n        @Nullable Pixmap pixmap;\n        Fi file;\n\n        public PackIndex(Fi file){\n            this.file = file;\n        }","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/tools/src/mindustry/tools/ImagePacker.java#L275-L311","documentation":"Thrown by the GenRegion constructor when name is null. GenRegion extends AtlasRegion and stores the name to identify a sprite region in the packing pipeline; a null name is treated as a programmer error, not user input, so it fails fast with IllegalArgumentException. This guard runs only inside the build-time ImagePacker tool, never in shipped game code.","triggerScenarios":"Invoking new GenRegion(null, path), or calling code that derives the name from a file path whose name resolved to null (e.g. a sprite entry with no filename, or a region generator that returns null on a missing mapping).","commonSituations":"Adding a new sprite whose pack.json entry has no name; refactoring region generation so the name argument is dropped; a malformed/empty filename in the assets list feeding a null name; an upstream change to Fi naming returning null on an unusual path.","solutions":["Trace the caller of 'new GenRegion(...)' and ensure the name argument is always a non-null, non-empty string.","If the name is derived from a file path, fall back to path.nameWithoutExtension() instead of passing null.","Add a unit test that constructs every region declared in pack.json and asserts a non-null name.","Fail earlier in the pipeline with a descriptive message naming the offending asset."],"exampleFix":"// before\ngen = new GenRegion(name, file);  // name may be null\n\n// after\nString regionName = name != null ? name : file.nameWithoutExtension();\nif(regionName == null || regionName.isEmpty()) throw new IllegalStateException(\"Region has no name: \" + file);\ngen = new GenRegion(regionName, file);","handlingStrategy":"validation","validationCode":"// Before constructing a GenRegion\nString regionName = name != null ? name : (path != null ? path.nameWithoutExtension() : null);\nif(regionName == null || regionName.isEmpty()){\n    throw new IllegalStateException(\"Cannot create region with null name for path: \" + path);\n}\nnew GenRegion(regionName, path);","typeGuard":"static boolean hasValidRegionName(String name, Fi path){\n    return name != null && !name.isEmpty() || (path != null && path.nameWithoutExtension() != null);\n}","tryCatchPattern":null,"preventionTips":["Always derive the region name from the asset filename so it can never be null.","Add a test that builds every region declared in pack.json and asserts a non-null name.","Fail at the asset-loading boundary with a descriptive message rather than deep in the constructor."],"tags":["tools","assets","validation","build"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}