Repository: netty/netty
File: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3Settings.java (Java)

Code before:
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Http3Settings{");
        boolean first = true;
        for (LongObjectMap.PrimitiveEntry<Long> e : settings.entries()) {
            if (!first) {
                sb.append(", ");
            }
            first = false;
            sb.append("0x").append(toHexString(e.key())).append('=').append(e.value());
        }
        return sb.append('}').toString();
    }

    /**
     * Validates a setting identifier and value pair against HTTP/3.
     * Note that it can only validate the valid HTTP/3 settings
     * Does not validate non-standard settings
     * @param identifier the setting identifier
     * @param value the setting value
     * @throws IllegalArgumentException if the identifier or value violates the protocol specification
     */
    private static void verifyStandardSetting(Http3SettingIdentifier identifier, Long value) {
        checkNotNull(value, "value");

        if (identifier == null) {
            return;
        }

        switch (identifier) {
            case HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY:
            case HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS:
            case HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE:
                if (value < 0) {
                    throw new IllegalArgumentException("Setting 0x" + toHexString(identifier.id())
                            + " invalid: " + value + " (must be >= 0)");
                }
                break;
            case HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL:
            case HTTP3_SETTINGS_H3_DATAGRAM:
                if (value != 0L && value != 1L) {
                    throw new IllegalArgumentException(
                            "Invalid: " + value + "for "
                                    + Http3SettingIdentifier.valueOf(String.valueOf(identifier))
                            + " (expected 0 or 1)");
                }
                break;
            default:
                if (value < 0) {
                    throw new IllegalArgumentException("Setting 0x"
                            + toHexString(identifier.id()) + " invalid: " + value);

Review comment (suggestion):
instead we should throw a `NullPointerException` rather, the caller already does the non null check (in `put`), so calling this with a null identified is a programming error and should be detected.

Code after:
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Http3Settings{");
        boolean first = true;
        for (LongObjectMap.PrimitiveEntry<Long> e : settings.entries()) {
            if (!first) {
                sb.append(", ");
            }
            first = false;
            sb.append("0x").append(toHexString(e.key())).append('=').append(e.value());
        }
        return sb.append('}').toString();
    }

    /**
     * Validates a setting identifier and value pair against HTTP/3.
     * Note that it can only validate the valid HTTP/3 settings
     * Does not validate non-standard settings
     * @param identifier the setting identifier
     * @param value the setting value
     * @throws IllegalArgumentException if the identifier or value violates the protocol specification
     */
    private static void verifyStandardSetting(Http3SettingIdentifier identifier, Long value) {
        checkNotNull(value, "value");
        checkNotNull(identifier, "identifier");

        switch (identifier) {
            case HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY:
            case HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS:
            case HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE:
                if (value < 0) {
                    throw new IllegalArgumentException("Setting 0x" + toHexString(identifier.id())
                            + " invalid: " + value + " (must be >= 0)");
                }
                break;
            case HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL:
            case HTTP3_SETTINGS_H3_DATAGRAM:
                if (value != 0L && value != 1L) {
                    throw new IllegalArgumentException(
                            "Invalid: " + value + "for "
                                    + Http3SettingIdentifier.valueOf(String.valueOf(identifier))
                            + " (expected 0 or 1)");
                }
                break;
            default:
                if (value < 0) {
                    throw new IllegalArgumentException("Setting 0x"
                            + toHexString(identifier.id()) + " invalid: " + value);
                }
        }
    }