libgdx/libgdx · error · IllegalArgumentException
extension cannot be null.
Error message
extension cannot be null.
What it means
Argument validation in OpenALLwjgl3Audio.registerSound: the extension key used for the sound-factory map cannot be null. Registering a supplier under a null key would make the map unusable for extension lookup, so it is rejected with IllegalArgumentException.
Source
Thrown at backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/audio/OpenALLwjgl3Audio.java:180
// Update last available devices
lastAvailableDevices = currentDevices;
}
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
return;
}
}
}
});
observerThread.setDaemon(true);
observerThread.start();
recentSounds = new OpenALSound[simultaneousSources];
}
public void registerSound (String extension, BiFunction<OpenALLwjgl3Audio, FileHandle, OpenALSound> soundSupplier) {
if (extension == null) throw new IllegalArgumentException("extension cannot be null.");
if (soundSupplier == null) throw new IllegalArgumentException("soundClass cannot be null.");
extensionToSoundClass.put(extension, soundSupplier);
}
public void registerMusic (String extension, BiFunction<OpenALLwjgl3Audio, FileHandle, OpenALMusic> soundSupplier) {
if (extension == null) throw new IllegalArgumentException("extension cannot be null.");
if (soundSupplier == null) throw new IllegalArgumentException("musicClass cannot be null.");
extensionToMusicClass.put(extension, soundSupplier);
}
public OpenALSound newSound (FileHandle file) {
String extension = file.extension().toLowerCase();
return newSound(file, extension);
}
public OpenALSound newSound (FileHandle file, String extension) {
if (file == null) throw new IllegalArgumentException("file cannot be null.");
BiFunction<OpenALLwjgl3Audio, FileHandle, OpenALSound> soundSupplier = extensionToSoundClass.get(extension);View on GitHub (pinned to 97f4086187)
Solutions
- Pass a concrete lowercase extension literal such as "ogg" or "mp3".
- If deriving from a filename, null/empty-check it before registering.
- Verify which overload you called — registerSound vs registerMusic take the same first parameter.
Example fix
// before
String ext = config.get("soundExt"); // null when missing
audio.registerSound(ext, supplier);
// after
String ext = config.get("soundExt");
if (ext == null || ext.isEmpty()) throw new IllegalStateException("soundExt missing in config");
audio.registerSound(ext.toLowerCase(), supplier); Defensive patterns
Strategy: validation
Validate before calling
if (ext == null || ext.isEmpty()) throw new IllegalArgumentException("ext required");
audio.registerSound(ext.toLowerCase(), supplier); Prevention
- Derive extensions from literals, not nullable config lookups.
- Add @NonNull annotations or Objects.requireNonNull at registration sites.
- Cover registration paths in unit tests.
When it happens
Trigger: Calling audio.registerSound(null, supplier), usually because the extension string was computed (e.g. file.extension() on a path with no dot, or from config) and came back null/blank.
Common situations: Plugin/mod systems registering codecs from config files, or dynamic extension derivation where a missing value flows through as null.
Related errors
- length cannot be < 0.
- file cannot be null.
- volume cannot be < 0: {}
- numSamples cannot be < 0.
- numSamples cannot be < 0.
AI-assisted analysis of libgdx/libgdx@97f4086187 (2026-08-14).
Data as JSON: /api/errors/4f7d2aae7c23e2a4.
Report an issue: GitHub.