This is an automated email from the ASF dual-hosted git repository.
jerryshao 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 71fb5f679e [#14775] fix(core): Return empty map from
maskSensitiveJobConf for null input (#14956)
71fb5f679e is described below
commit 71fb5f679efb567358bd5cb4031b733dc56c604d
Author: MaSai <[email protected]>
AuthorDate: Fri Nov 13 14:14:18 2026 +0800
[#14775] fix(core): Return empty map from maskSensitiveJobConf for null
input (#14956)
### What changes were proposed in this pull request?
Make `JobRuntimeTemplateMaskUtils.maskSensitiveJobConf` return an empty
map when `jobConf` is null, instead of null. Update
`TestJobRuntimeTemplateMaskUtils` accordingly, and add a
`JobEventDispatcher.runJob(..., null)` regression so `RunJobPreEvent` /
`RunJobEvent` no longer throw when building events.
Supersedes #14817.
### Why are the changes needed?
`JobEventDispatcher.runJob` masks `jobConf` for events, then
`RunJobPreEvent` / `RunJobEvent` call `ImmutableMap.copyOf(jobConf)`. A
null masked map caused an NPE before the job was created. The REST layer
already normalizes a missing `jobConf` to an empty map; the event path
did not.
Fixes #14775
### Does this PR introduce _any_ user-facing change?
No. Listeners receive an empty `jobConf` map when the caller passes
null, instead of failing during event construction.
### How was this patch tested?
```
./gradlew spotlessApply :core:test \
--tests 'org.apache.gravitino.job.TestJobRuntimeTemplateMaskUtils' \
--tests
'org.apache.gravitino.listener.api.event.TestJobEventDispatcher.testRunJobWithNullJobConfEmitsEmptyMapOnEvents'
\
--tests
'org.apache.gravitino.listener.api.event.TestJobEventDispatcher.testRunJobEventMasksSensitiveJobConf'
\
-PskipITs -PskipDockerTests=true
```
Co-authored-by: Cursor <[email protected]>
---
.../gravitino/job/JobRuntimeTemplateMaskUtils.java | 6 +++---
.../job/TestJobRuntimeTemplateMaskUtils.java | 2 +-
.../listener/api/event/TestJobEventDispatcher.java | 21 +++++++++++++++++++++
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git
a/core/src/main/java/org/apache/gravitino/job/JobRuntimeTemplateMaskUtils.java
b/core/src/main/java/org/apache/gravitino/job/JobRuntimeTemplateMaskUtils.java
index 71ae5dcfed..cd1ad5cc4d 100644
---
a/core/src/main/java/org/apache/gravitino/job/JobRuntimeTemplateMaskUtils.java
+++
b/core/src/main/java/org/apache/gravitino/job/JobRuntimeTemplateMaskUtils.java
@@ -81,12 +81,12 @@ public final class JobRuntimeTemplateMaskUtils {
* callers must pass the original map to job execution.
*
* @param jobConf runtime configuration from the runJob caller; may be null
- * @return a masked copy, or null when {@code jobConf} is null
+ * @return a masked copy, or an empty map when {@code jobConf} is null
*/
- @Nullable
public static Map<String, String> maskSensitiveJobConf(@Nullable Map<String,
String> jobConf) {
if (jobConf == null) {
- return null;
+ // Align with REST (null jobConf → empty map) so RunJob*Event
ImmutableMap.copyOf never NPE.
+ return new LinkedHashMap<>();
}
Map<String, String> masked = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : jobConf.entrySet()) {
diff --git
a/core/src/test/java/org/apache/gravitino/job/TestJobRuntimeTemplateMaskUtils.java
b/core/src/test/java/org/apache/gravitino/job/TestJobRuntimeTemplateMaskUtils.java
index 9a4bd1f396..5e36821073 100644
---
a/core/src/test/java/org/apache/gravitino/job/TestJobRuntimeTemplateMaskUtils.java
+++
b/core/src/test/java/org/apache/gravitino/job/TestJobRuntimeTemplateMaskUtils.java
@@ -249,7 +249,7 @@ public class TestJobRuntimeTemplateMaskUtils {
Assertions.assertFalse(masked.get("spark_conf").contains("jdbc-pw"));
Assertions.assertTrue(masked.get("spark_conf").contains("1g"));
Assertions.assertTrue(jobConf.get("updater_options").contains("arg-pw"));
-
Assertions.assertNull(JobRuntimeTemplateMaskUtils.maskSensitiveJobConf(null));
+
Assertions.assertTrue(JobRuntimeTemplateMaskUtils.maskSensitiveJobConf(null).isEmpty());
}
private static SparkJobTemplateDTO sparkWithArguments(List<String>
arguments) {
diff --git
a/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
b/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
index 11029484d7..c4ac6e036e 100644
---
a/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
+++
b/core/src/test/java/org/apache/gravitino/listener/api/event/TestJobEventDispatcher.java
@@ -499,6 +499,27 @@ public class TestJobEventDispatcher {
Assertions.assertTrue(conf.get("updater_options").contains("arg-pw"));
}
+ @Test
+ void testRunJobWithNullJobConfEmitsEmptyMapOnEvents() throws
NoSuchJobTemplateException {
+ // Regression for #14775: maskSensitiveJobConf(null) must not NPE
RunJob*Event constructors.
+ DummyEventListener listener = new DummyEventListener();
+ EventBus eventBus = new EventBus(Collections.singletonList(listener));
+ JobOperationDispatcher delegate = mock(JobOperationDispatcher.class);
+ when(delegate.runJob(any(String.class), any(String.class),
any())).thenReturn(jobEntity);
+ JobEventDispatcher maskingDispatcher = new JobEventDispatcher(eventBus,
delegate);
+
+ String templateName = jobTemplateEntity.name();
+ Assertions.assertDoesNotThrow(() -> maskingDispatcher.runJob("metalake",
templateName, null));
+
+ verify(delegate).runJob(eq("metalake"), eq(templateName), eq(null));
+ Map<String, String> preJobConf = ((RunJobPreEvent)
listener.popPreEvent()).jobConf();
+ Map<String, String> postJobConf = ((RunJobEvent)
listener.popPostEvent()).jobConf();
+ Assertions.assertNotNull(preJobConf);
+ Assertions.assertTrue(preJobConf.isEmpty());
+ Assertions.assertNotNull(postJobConf);
+ Assertions.assertTrue(postJobConf.isEmpty());
+ }
+
@Test
void testRunJobFailureEventMasksSensitiveJobConf() {
DummyEventListener listener = new DummyEventListener();