{"record":{"id":"7e9a9b5c427c9cc7","repo":"HMCL-dev/HMCL","slug":"authlib-injectors-json-urls-cannot-be-null","errorCode":null,"errorMessage":"authlib-injectors.json -> urls cannot be null.","messagePattern":"authlib-injectors\\.json -> urls cannot be null\\.","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/setting/AuthlibInjectorServers.java","lineNumber":62,"sourceCode":"\n    public static final String CONFIG_FILENAME = \"authlib-injectors.json\";\n\n    private static final Set<AuthlibInjectorServer> servers = new CopyOnWriteArraySet<>();\n\n    public static Set<AuthlibInjectorServer> getServers() {\n        return servers;\n    }\n\n    private final List<String> urls;\n\n    private AuthlibInjectorServers(List<String> urls) {\n        this.urls = urls;\n    }\n\n    @Override\n    public void validate() throws JsonParseException, TolerableValidationException {\n        if (this.urls == null) {\n            throw new JsonParseException(\"authlib-injectors.json -> urls cannot be null.\");\n        }\n    }\n\n    public static void init() {\n        Path configLocation;\n        Path jarPath = JarUtils.thisJarPath();\n        if (jarPath != null && Files.isRegularFile(jarPath) && Files.isWritable(jarPath)) {\n            configLocation = jarPath.getParent().resolve(CONFIG_FILENAME);\n        } else {\n            configLocation = Paths.get(CONFIG_FILENAME);\n        }\n\n        if (SettingsManager.isNewlyCreated() && Files.exists(configLocation)) {\n            AuthlibInjectorServers configInstance;\n            try {\n                configInstance = JsonUtils.fromJsonFile(configLocation, AuthlibInjectorServers.class);\n            } catch (IOException | JsonParseException e) {\n                LOG.warning(\"Malformed authlib-injectors.json\", e);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/setting/AuthlibInjectorServers.java#L44-L80","documentation":"AuthlibInjectorServers.validate enforces that the parsed authlib-injectors.json config contains a non-null \"urls\" array, throwing JsonParseException when it is null. This validation runs when HMCL loads or installs the authlib injector server list, guaranteeing the rest of the code can safely iterate the URLs.","triggerScenarios":"Loading or saving authlib-injectors.json whose JSON object has no \"urls\" key (or an explicit null) followed by a validate() call — e.g. during AuthlibInjectorServers.init() reading the config location, or deserializing a server entry from command-line/config input.","commonSituations":"Hand-edited or truncated authlib-injectors.json missing the urls array; a launcher distribution tool writes the file with only metadata; a tool expecting a different schema writes {\"server\": ...} without urls.","solutions":["Add the required \"urls\" array to authlib-injectors.json, e.g. {\"urls\": [\"https://authserver.example.com/api/yggdrasil\"]}","Delete the broken file so HMCL regenerates/ignores it, then re-add servers via the UI or -Dhmcl.authlib_injector_url parameter","Validate the JSON with a quick script (check json.urls is a non-null array) before shipping the file in your distribution","If generating the file programmatically, always serialize the urls field even when empty"],"exampleFix":"// before\n{ \"name\": \"Example Server\" }\n// after\n{ \"name\": \"Example Server\", \"urls\": [\"https://authserver.example.com/api/yggdrasil\"] }","handlingStrategy":"validation","validationCode":"JsonObject cfg = JsonParser.parseString(Files.readString(authlibInjectorsPath)).getAsJsonObject();\nif (!cfg.has(\"urls\") || !cfg.get(\"urls\").isJsonArray())\n    throw new IOException(\"authlib-injectors.json must contain a urls array\");","typeGuard":"static boolean hasValidUrls(JsonObject cfg) {\n    return cfg.has(\"urls\") && cfg.get(\"urls\").isJsonArray();\n}","tryCatchPattern":"try {\n    AuthlibInjectorServers.init();\n} catch (JsonParseException e) {\n    LOGGER.warning(\"Invalid authlib-injectors.json: \" + e.getMessage());\n    // regenerate or ignore the file and continue with no servers\n}","preventionTips":["Always include a urls array even when empty when generating the file","Validate the JSON before bundling it in a launcher distribution","Keep the file minimal and follow the documented schema exactly","Test the file loads in HMCL before shipping"],"tags":["json","config","authlib-injector","validation"],"backgroundTag":"missing-required-config-field","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}