Copilot commented on code in PR #9939:
URL: https://github.com/apache/gravitino/pull/9939#discussion_r2786325078


##########
common/src/main/java/org/apache/gravitino/Version.java:
##########
@@ -96,6 +96,16 @@ public static int[] parseVersionNumber(String versionString) 
{
 
     Matcher matcher = PATTERN.matcher(versionString);
     if (matcher.matches()) {
+      String releaseCandidateNumber = matcher.group(4);
+      if (releaseCandidateNumber != null) {
+        int rcNumber = Integer.parseInt(releaseCandidateNumber);
+        // We set an upper bound for RC number to prevent potential overflow 
issues, as we use RC
+        // number as part of the version number for comparison.
+        Preconditions.checkArgument(
+            rcNumber >= 0 && rcNumber <= 1000,
+            "Invalid RC version string %s, RC number must be between 0 and 
1000",
+            versionString);

Review Comment:
   Consider extracting `1000` into a named constant (e.g., `MAX_RC_NUMBER`) and 
reusing it in both the bounds check and the error message. This avoids 
duplicating the same magic number and makes future adjustments less error-prone.



##########
common/src/test/java/org/apache/gravitino/TestVersion.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.gravitino;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestVersion {
+
+  @Test
+  public void testParseReleaseCandidateVersions() {
+    Assertions.assertArrayEquals(new int[] {1, 1, 0}, 
Version.parseVersionNumber("1.1.0rc0"));
+    Assertions.assertArrayEquals(new int[] {1, 1, 0}, 
Version.parseVersionNumber("1.1.0rc1"));
+    Assertions.assertArrayEquals(new int[] {1, 1, 0}, 
Version.parseVersionNumber("1.1.0rc1000"));
+  }

Review Comment:
   Since the core change is a regex rewrite, the tests currently cover only 
`...rcN` inputs. Please add regression cases for previously-supported version 
formats (e.g., `1.1.0-SNAPSHOT` and `1.1.0.alpha`) and a couple invalid RC 
strings (like missing RC number) to ensure the updated pattern doesn’t 
accidentally reject/accept other forms.



##########
common/src/main/java/org/apache/gravitino/Version.java:
##########
@@ -96,6 +96,16 @@ public static int[] parseVersionNumber(String versionString) 
{
 
     Matcher matcher = PATTERN.matcher(versionString);
     if (matcher.matches()) {
+      String releaseCandidateNumber = matcher.group(4);
+      if (releaseCandidateNumber != null) {
+        int rcNumber = Integer.parseInt(releaseCandidateNumber);
+        // We set an upper bound for RC number to prevent potential overflow 
issues, as we use RC
+        // number as part of the version number for comparison.

Review Comment:
   The comment about preventing overflow because the RC number is used for 
version comparison is misleading: the RC number isn’t used in the returned 
version array or elsewhere in this method, and the regex already limits it to 4 
digits so `Integer.parseInt` overflow isn’t possible here. Please update/remove 
the comment to reflect the actual intent (domain validation), or incorporate 
the RC number into comparison logic if that’s the goal.
   ```suggestion
           // Validate RC number is within a supported range for Gravitino 
versioning semantics.
           // This is a domain constraint and is not used in numeric version 
comparison here.
   ```



-- 
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