AI REVIEWED
Module: cli
File: cli/format/FormatRegistry.java (~line 161-165)
Severity: Medium
Summary
register() accepts any FormatHandler without validating that formatId() is non-empty or that fileExtensions() returns a non-empty array. Empty or null format IDs would cause lookup failures.
Suggested Fix
public static void register(@NotNull final FormatHandler<?> handler) {
Preconditions.checkNotNull(handler, "handler must not be null");
String id = handler.formatId();
Preconditions.checkArgument(id != null && !id.isEmpty(), "formatId must not be empty");
String[] ext = handler.fileExtensions();
Preconditions.checkArgument(ext != null && ext.length > 0, "fileExtensions must not be empty");
HANDLERS.put(id, handler);
}