Konloch/bytecode-viewer · error · IllegalArgumentException
null key or factory
Error message
null key or factory
What it means
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.
Source
Thrown at src/main/java/the/bytecode/club/bytecodeviewer/bootloader/loader/AbstractLoaderFactory.java:45
* @author Bibl (don't ban me pls)
* @since 21 Jul 2015 00:18:07
*/
public final class AbstractLoaderFactory
{
private static final String DEFAULT_KEY = "default-factory";
private static final Map<String, LoaderFactory<?>> FACTORY_CACHE = new HashMap<>();
public static void register(LoaderFactory<?> factory)
{
register(DEFAULT_KEY, factory);
}
public static void register(String key, LoaderFactory<?> factory)
{
if (key == null || factory == null)
{
throw new IllegalArgumentException("null key or factory");
}
if (FACTORY_CACHE.containsKey(key))
{
throw new IllegalArgumentException("factory already registered with key: " + key);
}
FACTORY_CACHE.put(key, factory);
}
public static void unregister(String key)
{
if (key == null)
{
throw new IllegalArgumentException("null key");
}
if (!FACTORY_CACHE.containsKey(key))View on GitHub (pinned to 31430e0033)
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.
Example fix
// before
register(cfg.get("loaderKey"), maybeFactory);
// after
String key = cfg.get("loaderKey");
if (key != null && maybeFactory != null) register(key, maybeFactory); Defensive patterns
Strategy: validation
Validate before calling
if (key == null || key.isEmpty() || factory == null) { throw new IllegalStateException("register needs non-null key and factory"); }
AbstractLoaderFactory.register(key, factory); Type guard
boolean isRegistrable(String key, LoaderFactory<?> f) { return key != null && !key.isEmpty() && f != null; } Try / catch
try { AbstractLoaderFactory.register(key, factory); }
catch (IllegalArgumentException e) {
if ("null key or factory".equals(e.getMessage())) throw new ConfigException("loader key/factory missing", e);
throw e;
} Prevention
- Null-check config-derived keys before registration
- Never return null from factory providers — throw at construction
- Initialize the registry in one dedicated bootstrap method
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- null key
- factory already registered with key: ${key}
- factory doesn't key for key: ${key}
- '${codebase}' is not a directory
- Unknown constant pool tag ${tag}
AI-assisted analysis of Konloch/bytecode-viewer@31430e0033 (2026-09-05).
Data as JSON: /api/errors/60fc8b4e51c5e8ab.
Report an issue: GitHub.