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

yufei pushed a commit to branch fix/core-negative-policy-code
in repository https://gitbox.apache.org/repos/asf/polaris.git

commit 2345c54796b91e0c6d6f1a50c009b0cf8006f43d
Author: ci-bot <[email protected]>
AuthorDate: Mon Sep 1 17:23:08 2025 -0700

    Core: Prevent AIOOBE for negative policy codes in 
PredefinedPolicyTypes.fromCode; add unit test
---
 .../polaris/core/policy/PredefinedPolicyTypes.java |  2 +-
 .../core/policy/PredefinedPolicyTypesTest.java     | 44 ++++++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/policy/PredefinedPolicyTypes.java
 
b/polaris-core/src/main/java/org/apache/polaris/core/policy/PredefinedPolicyTypes.java
index 6cb86eb52..40128f979 100644
--- 
a/polaris-core/src/main/java/org/apache/polaris/core/policy/PredefinedPolicyTypes.java
+++ 
b/polaris-core/src/main/java/org/apache/polaris/core/policy/PredefinedPolicyTypes.java
@@ -88,7 +88,7 @@ public enum PredefinedPolicyTypes implements PolicyType {
    */
   @JsonCreator
   public static @Nullable PredefinedPolicyTypes fromCode(int code) {
-    if (code >= REVERSE_CODE_MAPPING_ARRAY.length) {
+    if (code < 0 || code >= REVERSE_CODE_MAPPING_ARRAY.length) {
       return null;
     }
 
diff --git 
a/polaris-core/src/test/java/org/apache/polaris/core/policy/PredefinedPolicyTypesTest.java
 
b/polaris-core/src/test/java/org/apache/polaris/core/policy/PredefinedPolicyTypesTest.java
new file mode 100644
index 000000000..97bfc2417
--- /dev/null
+++ 
b/polaris-core/src/test/java/org/apache/polaris/core/policy/PredefinedPolicyTypesTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.polaris.core.policy;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+
+class PredefinedPolicyTypesTest {
+
+  @Test
+  void fromCodeReturnsNullForNegative() {
+    assertThat(PredefinedPolicyTypes.fromCode(-1)).isNull();
+  }
+
+  @Test
+  void fromCodeReturnsTypeForValid() {
+    int code = PredefinedPolicyTypes.DATA_COMPACTION.getCode();
+    assertThat(PredefinedPolicyTypes.fromCode(code))
+        .isEqualTo(PredefinedPolicyTypes.DATA_COMPACTION);
+  }
+
+  @Test
+  void fromNameReturnsNullForUnknown() {
+    assertThat(PredefinedPolicyTypes.fromName("__unknown__")).isNull();
+  }
+}
+

Reply via email to