ronantakizawa/codereview-bench huggingface dataset:
Repository: netty/netty
File: transport-native-io_uring/src/test/java/io/netty/channel/uring/IoUringIoHandlerTest.java (Java)

Code before:
/*
 * Copyright 2025 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.channel.uring;

import io.netty.channel.IoHandler;
import io.netty.channel.IoHandlerFactory;
import org.junit.jupiter.api.Test;

public class IoUringIoHandlerTest {

    @Test
    public void testOptions() {
        IoUringIoHandlerConfiguration config = new IoUringIoHandlerConfiguration();
        config.setMaxBoundedWorker(2)
                .setMaxUnboundedWorker(2);
        IoHandlerFactory ioHandlerFactory = IoUringIoHandler.newFactory(config);
        IoHandler handler = ioHandlerFactory.newHandler();
        handler.destroy();
    }
}


Review comment (suggestion):
```suggestion

    @BeforeAll
    public static void loadJNI() {
        assumeTrue(IoUring.isAvailable());
    }
```

Code after:
/*
 * Copyright 2025 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.channel.uring;

import io.netty.channel.IoHandler;
import io.netty.channel.IoHandlerFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class IoUringIoHandlerTest {

    @BeforeAll
    public static void loadJNI() {
        assumeTrue(IoUring.isAvailable());
    }

    @Test
    public void testOptions() {
        IoUringIoHandlerConfiguration config = new IoUringIoHandlerConfiguration();
        config.setMaxBoundedWorker(2)
                .setMaxUnboundedWorker(2);
        IoHandlerFactory ioHandlerFactory = IoUringIoHandler.newFactory(config);
        IoHandler handler = ioHandlerFactory.newHandler();
        handler.destroy();
    }
}
Repository: netty/netty
File: transport-classes-io_uring/src/main/java/io/netty/channel/uring/RingBuffer.java (Java)

Code before:
    int fd() {
        return ioUringCompletionQueue.ringFd;
    }

    int features() {
        return features;
    }

    SubmissionQueue ioUringSubmissionQueue() {
        return this.ioUringSubmissionQueue;
    }

    CompletionQueue ioUringCompletionQueue() {
        return this.ioUringCompletionQueue;
    }

    void close() {
        ioUringSubmissionQueue.release();
        Native.ioUringExit(
                ioUringSubmissionQueue.submissionQueueArrayAddress,
                ioUringSubmissionQueue.ringEntries,
                ioUringSubmissionQueue.ringAddress,
                ioUringSubmissionQueue.ringSize,
                ioUringCompletionQueue.ringAddress,
                ioUringCompletionQueue.ringSize,
                ioUringSubmissionQueue.ringFd, ioUringSubmissionQueue.enterRingFd);
    }
}


Review comment (suggestion):
```suggestion
                ioUringSubmissionQueue.ringFd,
                ioUringSubmissionQueue.enterRingFd);
```

Code after:
    int fd() {
        return ioUringCompletionQueue.ringFd;
    }

    int features() {
        return features;
    }

    SubmissionQueue ioUringSubmissionQueue() {
        return this.ioUringSubmissionQueue;
    }

    CompletionQueue ioUringCompletionQueue() {
        return this.ioUringCompletionQueue;
    }

    void close() {
        ioUringSubmissionQueue.release();
        Native.ioUringExit(
                ioUringSubmissionQueue.submissionQueueArrayAddress,
                ioUringSubmissionQueue.ringEntries,
                ioUringSubmissionQueue.ringAddress,
                ioUringSubmissionQueue.ringSize,
                ioUringCompletionQueue.ringAddress,
                ioUringCompletionQueue.ringSize,
                ioUringSubmissionQueue.ringFd,
                ioUringSubmissionQueue.enterRingFd);
    }
}
Repository: netty/netty
File: codec-http2/src/test/java/io/netty/handler/codec/Http2FrameCodecSubClassTest.java (Java)

Code before:
/*
 * Copyright 2017 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.netty.handler.codec;


import io.netty.handler.codec.http2.DefaultHttp2Connection;
import io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder;
import io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder;
import io.netty.handler.codec.http2.DefaultHttp2FrameReader;
import io.netty.handler.codec.http2.DefaultHttp2FrameWriter;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;

Review comment (suggestion):
```suggestion
 * Copyright 2025 The Netty Project
```

Code after:
/*
 * Copyright 2025 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.netty.handler.codec;


import io.netty.handler.codec.http2.DefaultHttp2Connection;
import io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder;
import io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder;
import io.netty.handler.codec.http2.DefaultHttp2FrameReader;
import io.netty.handler.codec.http2.DefaultHttp2FrameWriter;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionDecoder;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
Repository: netty/netty
File: transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUring.java (Java)

Code before:
    }

    static boolean isIOUringAcceptNoWaitSupported() {
        return IORING_ACCEPT_NO_WAIT_SUPPORTED;
    }

    static boolean isRegisterIowqMaxWorkersSupported() {
        return IORING_REGISTER_IOWQ_MAX_WORKERS_SUPPORTED;
    }

    static boolean isIOUringSetupSubmitAllSupported() {
        return IORING_SETUP_SUBMIT_ALL_SUPPORTED;
    }

    static boolean isIOUringSetupSingleIssuerSupported() {
        return IORING_SETUP_SINGLE_ISSUER_SUPPORTED;
    }

    static boolean isIOUringSetupDeferTaskrunSupported() {
        return IORING_SETUP_DEFER_TASKRUN_SUPPORTED;
    }

    public static boolean isRegisterBufferRingSupported() {
        return IORING_REGISTER_BUFFER_RING_SUPPORTED;
    }
    public static boolean isRegisterBufferRingIncSupported() {
        return IORING_REGISTER_BUFFER_RING_INC_SUPPORTED;
    }

    public static void ensureAvailability() {
        if (UNAVAILABILITY_CAUSE != null) {
            throw (Error) new UnsatisfiedLinkError(
                    "failed to load the required native library").initCause(UNAVAILABILITY_CAUSE);
        }
    }

    public static Throwable unavailabilityCause() {
        return UNAVAILABILITY_CAUSE;
    }

    private IoUring() {
    }
}


Review comment (suggestion):
```suggestion
    }

    public static boolean isRegisterBufferRingIncSupported() {
```

Code after:
    }

    static boolean isIOUringAcceptNoWaitSupported() {
        return IORING_ACCEPT_NO_WAIT_SUPPORTED;
    }

    static boolean isRegisterIowqMaxWorkersSupported() {
        return IORING_REGISTER_IOWQ_MAX_WORKERS_SUPPORTED;
    }

    static boolean isIOUringSetupSubmitAllSupported() {
        return IORING_SETUP_SUBMIT_ALL_SUPPORTED;
    }

    static boolean isIOUringSetupSingleIssuerSupported() {
        return IORING_SETUP_SINGLE_ISSUER_SUPPORTED;
    }

    static boolean isIOUringSetupDeferTaskrunSupported() {
        return IORING_SETUP_DEFER_TASKRUN_SUPPORTED;
    }

    public static boolean isRegisterBufferRingSupported() {
        return IORING_REGISTER_BUFFER_RING_SUPPORTED;
    }

    public static boolean isRegisterBufferRingIncSupported() {
        return IORING_REGISTER_BUFFER_RING_INC_SUPPORTED;
    }

    public static void ensureAvailability() {
        if (UNAVAILABILITY_CAUSE != null) {
            throw (Error) new UnsatisfiedLinkError(
                    "failed to load the required native library").initCause(UNAVAILABILITY_CAUSE);
        }
    }

    public static Throwable unavailabilityCause() {
        return UNAVAILABILITY_CAUSE;
    }

    private IoUring() {
    }
}
Repository: netty/netty
File: transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUring.java (Java)

Code before:
    static boolean isSetupDeferTaskrunSupported() {
        return IORING_SETUP_DEFER_TASKRUN_SUPPORTED;
    }

    public static boolean isRegisterBufferRingSupported() {
        return IORING_REGISTER_BUFFER_RING_SUPPORTED;
    }

    public static boolean isRegisterBufferRingIncSupported() {
        return IORING_REGISTER_BUFFER_RING_INC_SUPPORTED;
    }

    public static void ensureAvailability() {
        if (UNAVAILABILITY_CAUSE != null) {
            throw (Error) new UnsatisfiedLinkError(
                    "failed to load the required native library").initCause(UNAVAILABILITY_CAUSE);
        }
    }

    public static Throwable unavailabilityCause() {
        return UNAVAILABILITY_CAUSE;
    }

    private IoUring() {
    }
}


Review comment (suggestion):
Perhaps making there methods to public could assist user in better adapting to different runtime environments
such as 
```java
if (!IoUinrg.isSpliceSupported) {
  pipeline.addlast(ChunkedWriteHandler);
}

if(IoUring.isRecvMultishotEnabled) {
  registerBufferRing(...)
}
```

Code after:
    }

    static boolean isRegisterIowqMaxWorkersSupported() {
        return IORING_REGISTER_IOWQ_MAX_WORKERS_SUPPORTED;
    }

    static boolean isSetupCqeSizeSupported() {
        return IORING_SETUP_CQ_SIZE_SUPPORTED;
    }

    static boolean isSetupSubmitAllSupported() {
        return IORING_SETUP_SUBMIT_ALL_SUPPORTED;
    }

    static boolean isSetupSingleIssuerSupported() {
        return IORING_SETUP_SINGLE_ISSUER_SUPPORTED;
    }

    static boolean isSetupDeferTaskrunSupported() {
        return IORING_SETUP_DEFER_TASKRUN_SUPPORTED;
    }

    /**
     * Returns if it is supported to use a buffer ring.
     *
     * @return {@code true} if supported, {@code false} otherwise.
     */
    public static boolean isRegisterBufferRingSupported() {
        return IORING_REGISTER_BUFFER_RING_SUPPORTED;
    }

    /**
     * Returns if it is supported to use an incremental buffer ring.
     *
     * @return {@code true} if supported, {@code false} otherwise.
     */
    public static boolean isRegisterBufferRingIncSupported() {
        return IORING_REGISTER_BUFFER_RING_INC_SUPPORTED;
    }

    /**
     * Returns if multi-shot ACCEPT is used or not.
     *
     * @return {@code true} if enabled, {@code false} otherwise.
     */
    public static boolean isAcceptMultishotEnabled() {
        return IORING_ACCEPT_MULTISHOT_ENABLED;
    }

    /**
     * Returns if multi-shot RECV is used or not.
Repository: netty/netty
File: codec-http/src/main/java/io/netty/handler/codec/http/HttpUtil.java (Java)

Code before:
    //
    //        long low() {
    //            return low;
    //        }
    //
    //        static boolean contains(byte bit, long high, long low) {
    //            if (bit < 0) {
    //                return false;
    //            }
    //            if (bit < 64) {
    //                return 0 != (low & 1L << bit);
    //            }
    //            return 0 != (high & 1L << bit - 64);
    //        }
    //    }

    // BitSet128 tokenChars = new BitSet128()
    //        .range('0', '9').range('a', 'z').range('A', 'Z') // Alphanumeric.
    //        .bits('-', '.', '_', '~') // Unreserved characters.
    //        .bits('!', '#', '$', '%', '&', '\'', '*', '+', '^', '`', '|'); // Token special characters.

    //this constants calculated by the above code
    private static final long TOKEN_CHARS_HIGH = 0x57ffffffc7fffffeL;
    private static final long TOKEN_CHARS_LOW = 0x3ff6cfa00000000L;

    private static boolean contains(byte bit) {
        if (bit < 0) {
            return false;
        }
        if (bit < 64) {
            return 0 != (TOKEN_CHARS_LOW & 1L << bit);
        }
        return 0 != (TOKEN_CHARS_HIGH & 1L << bit - 64);
    }

}


Review comment (suggestion):
`contains` is too generic a name once outside the `BitSet128` class. Let's call it `isValidTokenChar` or something like that.

Code after:
    //
    //        long low() {
    //            return low;
    //        }
    //
    //        static boolean contains(byte bit, long high, long low) {
    //            if (bit < 0) {
    //                return false;
    //            }
    //            if (bit < 64) {
    //                return 0 != (low & 1L << bit);
    //            }
    //            return 0 != (high & 1L << bit - 64);
    //        }
    //    }

    // BitSet128 tokenChars = new BitSet128()
    //        .range('0', '9').range('a', 'z').range('A', 'Z') // Alphanumeric.
    //        .bits('-', '.', '_', '~') // Unreserved characters.
    //        .bits('!', '#', '$', '%', '&', '\'', '*', '+', '^', '`', '|'); // Token special characters.

    //this constants calculated by the above code
    private static final long TOKEN_CHARS_HIGH = 0x57ffffffc7fffffeL;
    private static final long TOKEN_CHARS_LOW = 0x3ff6cfa00000000L;

    private static boolean isValidTokenChar(byte bit) {
        if (bit < 0) {
            return false;
        }
        if (bit < 64) {
            return 0 != (TOKEN_CHARS_LOW & 1L << bit);
        }
        return 0 != (TOKEN_CHARS_HIGH & 1L << bit - 64);
    }

}
Repository: netty/netty
File: common/src/main/java/io/netty/util/concurrent/EventExecutorChooserFactory.java (Java)

Code before:
/*
 * Copyright 2016 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.util.concurrent;

/**
 * Factory that creates new {@link EventExecutorChooser}s.
 */
public interface EventExecutorChooserFactory {

    /**
     * Returns a new {@link EventExecutorChooser}.
     */
    EventExecutorChooser newChooser(EventExecutor[] executors);

    /**
     * Chooses the next {@link EventExecutor} to use.
     */
    interface EventExecutorChooser {

        /**
         * Returns the new {@link EventExecutor} to use.
         */
        EventExecutor next();
    }

    /**
     * An {@link EventExecutorChooser} that exposes metrics for observation.
     */
    interface ObservableEventExecutorChooser extends EventExecutorChooser {

        /**
         * Returns the current number of active {@link EventExecutor}s.
         * @return the number of active executors.
         */
        int activeExecutorCount();
    }
}


Review comment (suggestion):
Not sure about this, maybe we can just read it outside, a pulling model, just as the ThreadPoolExecutor, an Observer seems overkill for me.

Code after:
    /**
     * Returns a new {@link EventExecutorChooser}.
     */
    EventExecutorChooser newChooser(EventExecutor[] executors);

    /**
     * Chooses the next {@link EventExecutor} to use.
     */
    interface EventExecutorChooser {

        /**
         * Returns the new {@link EventExecutor} to use.
         */
        EventExecutor next();
    }

    /**
     * An {@link EventExecutorChooser} that exposes metrics for observation.
     */
    interface ObservableEventExecutorChooser extends EventExecutorChooser {

        /**
         * Returns the current number of active {@link EventExecutor}s.
         * @return the number of active executors.
         */
        int activeExecutorCount();

        /**
         * Returns a list containing the last calculated utilization for each
         * {@link EventExecutor} in the group.
         *
         * @return an umodifiable view of the executor utilizations.
         */
        List<AutoScalingUtilizationMetric> executorUtilizations();
    }
}
Repository: netty/netty
File: transport/src/main/java/io/netty/channel/IoHandle.java (Java)

Code before:

    /**
     * Be called once there is something to handle.
     *
     * @param registration  the {@link IoRegistration} for this {@link IoHandle}.
     * @param ioEvent       the {@link IoEvent} that must be handled. The {@link IoEvent} is only valid
     *                      while this method is executed and so must not escape it.
     */
    void handle(IoRegistration registration, IoEvent ioEvent);

    /**
     * Called once this {@link IoHandle} was registered and so will start to receive events
     * via {@link #handle(IoRegistration, IoEvent)}.
     */
    default void registered() {
        // Noop by default.
    }

    /**
     * Called once this {@link IoHandle} was unregistered and so will not receive any more events
     * via {@link #handle(IoRegistration, IoEvent)}.
     */
    default void unregistered() {
        // Noop by default.
    }
}


Review comment (suggestion):
I think it'd make sense to add a note to the javadoc on how this is different from close, in terms of the handle lifecycle.

Code after:
 * was registered via {@link IoHandler#register(IoHandle)}.
 */
public interface IoHandle extends AutoCloseable {

    /**
     * Be called once there is something to handle.
     *
     * @param registration  the {@link IoRegistration} for this {@link IoHandle}.
     * @param ioEvent       the {@link IoEvent} that must be handled. The {@link IoEvent} is only valid
     *                      while this method is executed and so must not escape it.
     */
    void handle(IoRegistration registration, IoEvent ioEvent);

    /**
     * Called once this {@link IoHandle} was registered and so will start to receive events
     * via {@link #handle(IoRegistration, IoEvent)}.
     */
    default void registered() {
        // Noop by default.
    }

    /**
     * Called once this {@link IoHandle} was unregistered and so will not receive any more events
     * via {@link #handle(IoRegistration, IoEvent)}.
     */
    default void unregistered() {
        // Noop by default.
    }

    /**
     * Called once the {@link IoHandle} should be closed. Even once this method is called this handle might
     * still receive events via {@link #handle(IoRegistration, IoEvent)} (if it was previous be registered and so its
     * {@link #registered()} method was called) until the {@link #unregistered()} method is called.
     */
    void close() throws Exception;
}
Repository: netty/netty
File: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicStreamResetException.java (Java)

Code before:
/*
 * Copyright 2020 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.handler.codec.quic;

/**
 * Signals a stream reset.
 */
public class QuicStreamResetException extends QuicStreamException {

    private final long applicationProtocolCode;

    public QuicStreamResetException(String message, long applicationProtocolCode) {
        super(message);

        this.applicationProtocolCode = applicationProtocolCode;
    }

    /**
     * Returns the optional application protocol error code set on {@code RESET_STREAM} frames.
     *
     * Note: this is not yet implemented for {@code STOP_SENDING} frames.
     *
     * @return the optional application protocol error code or {@code -1} when no such code is provided.
     */
    public long applicationProtocolCode() {
        return applicationProtocolCode;
    }
}


Review comment (suggestion):
```suggestion
public final class QuicStreamResetException extends QuicStreamException {
```

Code after:
/*
 * Copyright 2025 The Netty Project
 *
 * The Netty Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package io.netty.handler.codec.quic;

/**
 * Signals a stream reset.
 */
public final class QuicStreamResetException extends QuicException {

    private final long applicationProtocolCode;

    public QuicStreamResetException(String message, long applicationProtocolCode) {
        super(message);

        this.applicationProtocolCode = applicationProtocolCode;
    }

    /**
     * Returns the optional application protocol error code set on {@code RESET_STREAM} frames.
     *
     * Note: this is not yet implemented for {@code STOP_SENDING} frames.
     *
     * @return the optional application protocol error code or {@code -1} when no such code is provided.
     */
    public long applicationProtocolCode() {
        return applicationProtocolCode;
    }
}