{"record":{"id":"4f7d2aae7c23e2a4","repo":"libgdx/libgdx","slug":"extension-cannot-be-null-4f7d2a","errorCode":null,"errorMessage":"extension cannot be null.","messagePattern":"extension cannot be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/audio/OpenALLwjgl3Audio.java","lineNumber":180,"sourceCode":"\t\t\t\t\t\t// Update last available devices\n\t\t\t\t\t\tlastAvailableDevices = currentDevices;\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tThread.sleep(1000);\n\t\t\t\t\t} catch (InterruptedException ignored) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tobserverThread.setDaemon(true);\n\t\tobserverThread.start();\n\n\t\trecentSounds = new OpenALSound[simultaneousSources];\n\t}\n\n\tpublic void registerSound (String extension, BiFunction<OpenALLwjgl3Audio, FileHandle, OpenALSound> soundSupplier) {\n\t\tif (extension == null) throw new IllegalArgumentException(\"extension cannot be null.\");\n\t\tif (soundSupplier == null) throw new IllegalArgumentException(\"soundClass cannot be null.\");\n\t\textensionToSoundClass.put(extension, soundSupplier);\n\t}\n\n\tpublic void registerMusic (String extension, BiFunction<OpenALLwjgl3Audio, FileHandle, OpenALMusic> soundSupplier) {\n\t\tif (extension == null) throw new IllegalArgumentException(\"extension cannot be null.\");\n\t\tif (soundSupplier == null) throw new IllegalArgumentException(\"musicClass cannot be null.\");\n\t\textensionToMusicClass.put(extension, soundSupplier);\n\t}\n\n\tpublic OpenALSound newSound (FileHandle file) {\n\t\tString extension = file.extension().toLowerCase();\n\t\treturn newSound(file, extension);\n\t}\n\n\tpublic OpenALSound newSound (FileHandle file, String extension) {\n\t\tif (file == null) throw new IllegalArgumentException(\"file cannot be null.\");\n\t\tBiFunction<OpenALLwjgl3Audio, FileHandle, OpenALSound> soundSupplier = extensionToSoundClass.get(extension);","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/libgdx/libgdx/blob/97f40861878058087be0685ca167ddfde132134b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/audio/OpenALLwjgl3Audio.java#L162-L198","documentation":"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.","triggerScenarios":"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.","commonSituations":"Plugin/mod systems registering codecs from config files, or dynamic extension derivation where a missing value flows through as null.","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."],"exampleFix":"// before\nString ext = config.get(\"soundExt\"); // null when missing\naudio.registerSound(ext, supplier);\n\n// after\nString ext = config.get(\"soundExt\");\nif (ext == null || ext.isEmpty()) throw new IllegalStateException(\"soundExt missing in config\");\naudio.registerSound(ext.toLowerCase(), supplier);","handlingStrategy":"validation","validationCode":"if (ext == null || ext.isEmpty()) throw new IllegalArgumentException(\"ext required\");\naudio.registerSound(ext.toLowerCase(), supplier);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive extensions from literals, not nullable config lookups.","Add @NonNull annotations or Objects.requireNonNull at registration sites.","Cover registration paths in unit tests."],"tags":["audio","validation","argument-error","libgdx"],"backgroundTag":null,"analyzedSha":"97f40861878058087be0685ca167ddfde132134b","analyzedAt":"2026-08-14T10:52:53.492Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}