This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 5588785566 [#7594] fix(restutils): correct loop condition in port 
range logic (#7595)
5588785566 is described below

commit 5588785566f3a189abc99e15d2941b34f7954eca
Author: Nithish Kumar S <[email protected]>
AuthorDate: Mon Jul 7 15:00:50 2025 +0530

    [#7594] fix(restutils): correct loop condition in port range logic (#7595)
    
    ### What changes were proposed in this pull request?
    
    This Pull Request fixes a logical error in the for loop condition in the
    RESTUtils.java file. The for loop previously used logical OR (`||`)
    operator and that has been changed to logical AND (`&&`) operator.
    
    ### Why are the changes needed?
    By using `||` operator, the loop condition could result in loop
    exceeding the intended port range **or** retry limit. Changing to `&&`
    operator ensures the loop condition does not exceed the port range
    **and** maximum retry count, preventing unintended behavior.
    
    Fix: #(7594)
    
    ### Does this PR introduce _any_ user-facing change?
    No user-facing changes.
    
    ### How was this patch tested?
    The loop logic was manually verified and no unit tests were added.
---
 common/src/main/java/org/apache/gravitino/rest/RESTUtils.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java 
b/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
index 4c25cbfd4d..98ef6a0dc0 100644
--- a/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
+++ b/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
@@ -160,7 +160,7 @@ public class RESTUtils {
 
     Random random = new Random();
     final int maxRetry = 200;
-    for (int i = portRangeStart; i <= portRangeEnd || i < portRangeStart + 
maxRetry; ++i) {
+    for (int i = portRangeStart; i <= portRangeEnd && i < portRangeStart + 
maxRetry; ++i) {
       int randomNumber = random.nextInt(portRangeEnd - portRangeStart + 1) + 
portRangeStart;
       try (ServerSocket socket = new ServerSocket(randomNumber)) {
         return socket.getLocalPort();

Reply via email to