You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polaris.apache.org by di...@apache.org on 2026/10/22 21:32:26 UTC

(polaris) branch main updated: Restore strict boolean validation for the maintenance policy enable field (#5735)

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

dimas-b pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new a30edecb38 Restore strict boolean validation for the maintenance policy enable field (#5735)
a30edecb38 is described below

commit a30edecb38eadf872a81d0a687c2e1802d303329
Author: Prithvi S <pr...@gmail.com>
AuthorDate: Fri Oct 23 03:02:20 2026 +0530

    Restore strict boolean validation for the maintenance policy enable field (#5735)
    
    Maintenance policy content parsing moved to the Jackson 3 (tools.jackson)
    mapper, but the strict boolean check on the enable field was still wired
    through a Jackson 2 databind @JsonDeserialize annotation referencing a
    Jackson 2 JsonDeserializer. Jackson 3 ignores the Jackson 2 databind
    annotation, so StrictBooleanDeserializer never ran and the mapper's default
    lenient coercion applied instead, accepting values such as "TRUE", 1 and 0.
    
    Port StrictBooleanDeserializer to the Jackson 3 ValueDeserializer API and
    switch the annotation to tools.jackson.databind.annotation.JsonDeserialize,
    applied to the enable creator parameter (the binding point for creator-based
    deserialization). Behavior now matches the original intent: only JSON
    true/false and the lowercase string forms are accepted; everything else is
    rejected with InvalidPolicyException.
    
    Add parameterized tests covering the previously-accepted values ("TRUE",
    "False", "yes", 1, 0) as rejections, and confirm true/false and "true"/"false"
    are still accepted. The rejection test fails against the old wiring and passes
    with the port.
---
 CHANGELOG.md                                       |  6 +++++
 .../policy/content/StrictBooleanDeserializer.java  | 13 +++++------
 .../maintenance/BaseMaintenancePolicyContent.java  |  6 +++--
 .../core/policy/MaintenancePolicyContentTest.java  | 26 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 08b22368ac..f7144ee09d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -128,6 +128,12 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
 
 - NoSQL commits resend unresolved object writes on retry, preventing successful commits from
   referencing objects left unwritten by a previous attempt.
+- Maintenance policy content now rejects non-boolean values for the `enable` field again. The
+  strict boolean check (`StrictBooleanDeserializer`) stopped running when policy parsing moved to
+  Jackson 3, because it was wired through a Jackson 2 `@JsonDeserialize` annotation that the Jackson
+  3 mapper ignores. As a result values such as `"TRUE"`, `1` and `0` were leniently coerced instead
+  of rejected. The deserializer is ported to the Jackson 3 API and applied to the `enable` creator
+  parameter, so only JSON `true`/`false` (and the lowercase string forms) are accepted.
 - The H2 relational JDBC init script no longer overwrites the recorded schema version. It now seeds
   the `version` table only when absent, matching the `ON CONFLICT DO NOTHING` behavior of the
   PostgreSQL and CockroachDB scripts. Previously, running bootstrap against an older, unmigrated H2
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/policy/content/StrictBooleanDeserializer.java b/polaris-core/src/main/java/org/apache/polaris/core/policy/content/StrictBooleanDeserializer.java
index 3c54d10d1d..d56eb6a390 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/policy/content/StrictBooleanDeserializer.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/policy/content/StrictBooleanDeserializer.java
@@ -18,16 +18,15 @@
  */
 package org.apache.polaris.core.policy.content;
 
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.DeserializationContext;
-import com.fasterxml.jackson.databind.JsonDeserializer;
-import java.io.IOException;
 import org.apache.polaris.core.policy.validator.InvalidPolicyException;
+import tools.jackson.core.JsonParser;
+import tools.jackson.databind.DeserializationContext;
+import tools.jackson.databind.ValueDeserializer;
 
-public class StrictBooleanDeserializer extends JsonDeserializer<Boolean> {
+public class StrictBooleanDeserializer extends ValueDeserializer<Boolean> {
   @Override
-  public Boolean deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
-    String text = p.getText();
+  public Boolean deserialize(JsonParser p, DeserializationContext ctxt) {
+    String text = p.getValueAsString();
     if ("true".equals(text)) {
       return Boolean.TRUE;
     } else if ("false".equals(text)) {
diff --git a/polaris-core/src/main/java/org/apache/polaris/core/policy/content/maintenance/BaseMaintenancePolicyContent.java b/polaris-core/src/main/java/org/apache/polaris/core/policy/content/maintenance/BaseMaintenancePolicyContent.java
index a825e87ba3..376606a918 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/policy/content/maintenance/BaseMaintenancePolicyContent.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/policy/content/maintenance/BaseMaintenancePolicyContent.java
@@ -20,13 +20,13 @@ package org.apache.polaris.core.policy.content.maintenance;
 
 import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 import com.google.common.base.Strings;
 import java.util.Map;
 import java.util.Set;
 import org.apache.polaris.core.policy.content.PolicyContent;
 import org.apache.polaris.core.policy.content.StrictBooleanDeserializer;
 import org.apache.polaris.core.policy.validator.InvalidPolicyException;
+import tools.jackson.databind.annotation.JsonDeserialize;
 
 public abstract class BaseMaintenancePolicyContent implements PolicyContent {
   @JsonDeserialize(using = StrictBooleanDeserializer.class)
@@ -37,7 +37,9 @@ public abstract class BaseMaintenancePolicyContent implements PolicyContent {
 
   @JsonCreator
   public BaseMaintenancePolicyContent(
-      @JsonProperty(value = "enable", required = true) boolean enable) {
+      @JsonProperty(value = "enable", required = true)
+          @JsonDeserialize(using = StrictBooleanDeserializer.class)
+          boolean enable) {
     this.enable = enable;
   }
 
diff --git a/polaris-core/src/test/java/org/apache/polaris/core/policy/MaintenancePolicyContentTest.java b/polaris-core/src/test/java/org/apache/polaris/core/policy/MaintenancePolicyContentTest.java
index a6157bfd92..ba6cd3ac83 100644
--- a/polaris-core/src/test/java/org/apache/polaris/core/policy/MaintenancePolicyContentTest.java
+++ b/polaris-core/src/test/java/org/apache/polaris/core/policy/MaintenancePolicyContentTest.java
@@ -154,6 +154,32 @@ public class MaintenancePolicyContentTest {
         .hasMessageContaining("Invalid policy");
   }
 
+  @ParameterizedTest
+  @MethodSource("policyTypes")
+  void testEnableRejectsNonBooleanValues(PredefinedPolicyTypes policyTypes) {
+    var parser = getParser(policyTypes);
+    // The strict boolean deserializer accepts only JSON true/false (and the lowercase string
+    // forms). Anything else Jackson would otherwise leniently coerce - a differently cased string,
+    // or the numbers 1 and 0 - must be rejected.
+    for (var enableValue : new String[] {"\"TRUE\"", "\"False\"", "\"yes\"", "1", "0"}) {
+      var invalidPolicy = "{\"enable\": " + enableValue + "}";
+      assertThatThrownBy(() -> parser.apply(invalidPolicy))
+          .as("enable=%s must be rejected", enableValue)
+          .isInstanceOf(InvalidPolicyException.class)
+          .hasMessageContaining("Invalid policy");
+    }
+  }
+
+  @ParameterizedTest
+  @MethodSource("policyTypes")
+  void testEnableAcceptsBooleansAndLowercaseStrings(PredefinedPolicyTypes policyTypes) {
+    var parser = getParser(policyTypes);
+    assertThat(parser.apply("{\"enable\": true}").enabled()).isTrue();
+    assertThat(parser.apply("{\"enable\": false}").enabled()).isFalse();
+    assertThat(parser.apply("{\"enable\": \"true\"}").enabled()).isTrue();
+    assertThat(parser.apply("{\"enable\": \"false\"}").enabled()).isFalse();
+  }
+
   @Test
   public void testValidOrphanFileRemovalPolicyContent() {
     assertThat(