Skip to content

[Bug]: FormatRegistry.register() does not validate formatId or extensions #204

@Splatcrafter

Description

@Splatcrafter

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions