RockteMQ-AI commented on code in PR #2198:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/2198#discussion_r3784122582


##########
server/src/main/java/org/apache/rocketmq/studio/provider/InstanceProvider.java:
##########
@@ -54,8 +54,9 @@ public interface InstanceProvider {
     default TopicConsumerPageVO getTopicConsumersPage(String instanceId, 
String topicName, int page, int pageSize) {
         List<TopicConsumerVO> consumers = getTopicConsumers(instanceId, 
topicName);
         int total = consumers.size();
-        int from = Math.min((page - 1) * pageSize, total);
-        int to = Math.min(from + pageSize, total);
+        long offset = ((long) page - 1) * pageSize;

Review Comment:
   Good fix — `(page - 1) * pageSize` overflows to a negative number when 
`page` is large (e.g. `Integer.MAX_VALUE`), causing `subList()` to throw 
`IndexOutOfBoundsException`. Casting to `long` first is the correct approach, 
and the subsequent `Math.min(offset, total)` ensures the result fits back into 
`int` safely.



##########
server/src/test/java/org/apache/rocketmq/studio/provider/InstanceProviderTest.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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
+ *
+ *     http://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 org.apache.rocketmq.studio.provider;
+
+import java.util.Arrays;
+import org.apache.rocketmq.studio.instance.topic.TopicConsumerPageVO;
+import org.apache.rocketmq.studio.instance.topic.TopicConsumerVO;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class InstanceProviderTest {
+
+    @Test
+    public void getTopicConsumersPageShouldHandleLargePageNumberTest() {
+        InstanceProvider provider = mock(InstanceProvider.class);
+        when(provider.getTopicConsumers("instance-a", 
"orders")).thenReturn(Arrays.asList(

Review Comment:
   Well-structured test — using `Integer.MAX_VALUE` as the page number directly 
exercises the overflow path. The assertions verify both the empty result and 
the correct total count.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to