{"record":{"id":"60fc8b4e51c5e8ab","repo":"Konloch/bytecode-viewer","slug":"null-key-or-factory","errorCode":null,"errorMessage":"null key or factory","messagePattern":"null key or factory","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/the/bytecode/club/bytecodeviewer/bootloader/loader/AbstractLoaderFactory.java","lineNumber":45,"sourceCode":" * @author Bibl (don't ban me pls)\n * @since 21 Jul 2015 00:18:07\n */\npublic final class AbstractLoaderFactory\n{\n\n    private static final String DEFAULT_KEY = \"default-factory\";\n    private static final Map<String, LoaderFactory<?>> FACTORY_CACHE = new HashMap<>();\n\n    public static void register(LoaderFactory<?> factory)\n    {\n        register(DEFAULT_KEY, factory);\n    }\n\n    public static void register(String key, LoaderFactory<?> factory)\n    {\n        if (key == null || factory == null)\n        {\n            throw new IllegalArgumentException(\"null key or factory\");\n        }\n\n        if (FACTORY_CACHE.containsKey(key))\n        {\n            throw new IllegalArgumentException(\"factory already registered with key: \" + key);\n        }\n\n        FACTORY_CACHE.put(key, factory);\n    }\n\n    public static void unregister(String key)\n    {\n        if (key == null)\n        {\n            throw new IllegalArgumentException(\"null key\");\n        }\n\n        if (!FACTORY_CACHE.containsKey(key))","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/Konloch/bytecode-viewer/blob/31430e0033fa220db566b5ef461256727ff6793b/src/main/java/the/bytecode/club/bytecodeviewer/bootloader/loader/AbstractLoaderFactory.java#L27-L63","documentation":"Static guard in AbstractLoaderFactory.register: the loader-factory registry rejects a registration where the key or the factory instance is null. It ensures the FACTORY_CACHE map only ever holds valid key->factory pairs so later lookups (find/unregister) behave predictably.","triggerScenarios":"Calling AbstractLoaderFactory.register(null, factory), register(key, null), or register(null, null), typically because the key was built from an unchecked config value or the factory construction failed upstream and returned null.","commonSituations":"Building a plugin/extension system where loader keys come from user config files or environment variables that are unset; factory providers returned null instead of throwing during initialization.","solutions":["Ensure the key string is non-null (and sensible: non-empty, unique) before calling register.","Ensure the LoaderFactory instance is fully constructed before registration; throw at construction time if it cannot be created.","Wrap the register call in validation or null-checks on both arguments.","Log/collect config errors at startup rather than passing nulls through."],"exampleFix":"// before\nregister(cfg.get(\"loaderKey\"), maybeFactory);\n// after\nString key = cfg.get(\"loaderKey\");\nif (key != null && maybeFactory != null) register(key, maybeFactory);","handlingStrategy":"validation","validationCode":"if (key == null || key.isEmpty() || factory == null) { throw new IllegalStateException(\"register needs non-null key and factory\"); }\nAbstractLoaderFactory.register(key, factory);","typeGuard":"boolean isRegistrable(String key, LoaderFactory<?> f) { return key != null && !key.isEmpty() && f != null; }","tryCatchPattern":"try { AbstractLoaderFactory.register(key, factory); }\ncatch (IllegalArgumentException e) {\n    if (\"null key or factory\".equals(e.getMessage())) throw new ConfigException(\"loader key/factory missing\", e);\n    throw e;\n}","preventionTips":["Null-check config-derived keys before registration","Never return null from factory providers — throw at construction","Initialize the registry in one dedicated bootstrap method"],"tags":["java","loader","registry","null-check"],"backgroundTag":"null-argument-validation","analyzedSha":"31430e0033fa220db566b5ef461256727ff6793b","analyzedAt":"2026-09-05T18:22:22.725Z","contentChangedAt":"2026-09-05T18:22:22.725Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}