This is an automated email from the ASF dual-hosted git repository.
yuqi1129 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 6f47cc24e1 [#13236] fix(common): override rules() in CustomContentDTO
to return customRules (#13237)
6f47cc24e1 is described below
commit 6f47cc24e1a44045baa93544037512b2a3a5d97f
Author: YangJie <[email protected]>
AuthorDate: Fri Sep 18 11:42:20 2026 -0400
[#13236] fix(common): override rules() in CustomContentDTO to return
customRules (#13237)
### What changes were proposed in this pull request?
`CustomContentDTO` now overrides `rules()` to return `customRules`,
restoring symmetry with the domain `CustomContent` and the sibling
`IcebergCompactionContentDTO`.
### Why are the changes needed?
It inherited `PolicyContent.rules()`, whose default throws
`UnsupportedOperationException`, so code holding the deserialized DTO
got an exception where the domain object returned the rules.
Fix: #13236
### Does this PR introduce _any_ user-facing change?
No API change. `CustomContentDTO.rules()` now returns `customRules`
instead of throwing `UnsupportedOperationException`. The standard REST
round-trip converts to the domain object and is unaffected.
### How was this patch tested?
Added `TestPolicyContentDTO`, which pins that `CustomContentDTO.rules()`
returns `customRules`; it fails on the pre-fix tree with
`UnsupportedOperationException` and passes after the fix.
---
.../gravitino/dto/policy/PolicyContentDTO.java | 5 +++
.../gravitino/dto/policy/TestPolicyContentDTO.java | 45 ++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git
a/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
b/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
index c9d6cb0f4b..5bde7f9af1 100644
--- a/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
+++ b/common/src/main/java/org/apache/gravitino/dto/policy/PolicyContentDTO.java
@@ -63,6 +63,11 @@ public interface PolicyContentDTO extends PolicyContent {
return customRules;
}
+ @Override
+ public Map<String, Object> rules() {
+ return customRules;
+ }
+
@Override
public Set<MetadataObject.Type> supportedObjectTypes() {
return supportedObjectTypes;
diff --git
a/common/src/test/java/org/apache/gravitino/dto/policy/TestPolicyContentDTO.java
b/common/src/test/java/org/apache/gravitino/dto/policy/TestPolicyContentDTO.java
new file mode 100644
index 0000000000..1f37c74c72
--- /dev/null
+++
b/common/src/test/java/org/apache/gravitino/dto/policy/TestPolicyContentDTO.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dto.policy;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.Map;
+import org.apache.gravitino.MetadataObject;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestPolicyContentDTO {
+
+ @Test
+ public void testCustomContentDtoRulesReturnsCustomRules() {
+ Map<String, Object> customRules = ImmutableMap.of("rule1", "value1");
+ PolicyContentDTO.CustomContentDTO content =
+ PolicyContentDTO.CustomContentDTO.builder()
+ .withCustomRules(customRules)
+ .withProperties(ImmutableMap.of("k", "v"))
+
.withSupportedObjectTypes(ImmutableSet.of(MetadataObject.Type.TABLE))
+ .build();
+
+ // Before the fix, CustomContentDTO inherited PolicyContent.rules() which
throws
+ // UnsupportedOperationException, even though the domain CustomContent
returns its
+ // customRules from rules().
+ Assertions.assertEquals(customRules, content.rules());
+ }
+}