You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ur...@apache.org on 2026/08/21 07:05:24 UTC
(spark) branch branch-4.3 updated: [SPARK-58922][CORE] Extract a null/empty MDC-array check in SparkLogger
This is an automated email from the ASF dual-hosted git repository.
uros-b pushed a commit to branch branch-4.3
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.3 by this push:
new afd1458172fb [SPARK-58922][CORE] Extract a null/empty MDC-array check in SparkLogger
afd1458172fb is described below
commit afd1458172fb69a8fce35e7e3a3d5f638defbefa
Author: Uros <22...@users.noreply.github.com>
AuthorDate: Fri Aug 21 07:04:56 2026 +0000
[SPARK-58922][CORE] Extract a null/empty MDC-array check in SparkLogger
### What changes were proposed in this pull request?
Extracts the repeated `mdcs == null || mdcs.length == 0` guard in `SparkLogger` into a private helper `isNullOrEmpty(MDC[] mdcs)`, and routes the six call sites (the `MDC...`-varargs `error`/`warn`/`info` overloads) through it.
### Why are the changes needed?
The same null/empty check was duplicated across six logging methods. Naming it once removes the duplication and gives a single place for the guard. No behavior change.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Existing tests. The helper returns exactly the previous boolean expression, so behavior is unchanged.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
Closes #58181 from uros-b/cleanup-sparklogger-mdc-check.
Authored-by: Uros <22...@users.noreply.github.com>
Signed-off-by: Uros Bojanic <22...@users.noreply.github.com>
(cherry picked from commit fa3fb94bb2a44c2ec70b36b370a7d8b6f17e8af0)
Signed-off-by: Uros Bojanic <22...@users.noreply.github.com>
---
.../main/java/org/apache/spark/internal/SparkLogger.java | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/common/utils-java/src/main/java/org/apache/spark/internal/SparkLogger.java b/common/utils-java/src/main/java/org/apache/spark/internal/SparkLogger.java
index 84d6d7cf4238..ca7da3abff83 100644
--- a/common/utils-java/src/main/java/org/apache/spark/internal/SparkLogger.java
+++ b/common/utils-java/src/main/java/org/apache/spark/internal/SparkLogger.java
@@ -96,7 +96,7 @@ public class SparkLogger {
}
public void error(String msg, MDC... mdcs) {
- if (mdcs == null || mdcs.length == 0) {
+ if (isNullOrEmpty(mdcs)) {
slf4jLogger.error(msg);
} else if (slf4jLogger.isErrorEnabled()) {
withLogContext(msg, mdcs, null, mt -> slf4jLogger.error(mt.message));
@@ -104,7 +104,7 @@ public class SparkLogger {
}
public void error(String msg, Throwable throwable, MDC... mdcs) {
- if (mdcs == null || mdcs.length == 0) {
+ if (isNullOrEmpty(mdcs)) {
slf4jLogger.error(msg, throwable);
} else if (slf4jLogger.isErrorEnabled()) {
withLogContext(msg, mdcs, throwable, mt -> slf4jLogger.error(mt.message, mt.throwable));
@@ -124,7 +124,7 @@ public class SparkLogger {
}
public void warn(String msg, MDC... mdcs) {
- if (mdcs == null || mdcs.length == 0) {
+ if (isNullOrEmpty(mdcs)) {
slf4jLogger.warn(msg);
} else if (slf4jLogger.isWarnEnabled()) {
withLogContext(msg, mdcs, null, mt -> slf4jLogger.warn(mt.message));
@@ -132,7 +132,7 @@ public class SparkLogger {
}
public void warn(String msg, Throwable throwable, MDC... mdcs) {
- if (mdcs == null || mdcs.length == 0) {
+ if (isNullOrEmpty(mdcs)) {
slf4jLogger.warn(msg, throwable);
} else if (slf4jLogger.isWarnEnabled()) {
withLogContext(msg, mdcs, throwable, mt -> slf4jLogger.warn(mt.message, mt.throwable));
@@ -152,7 +152,7 @@ public class SparkLogger {
}
public void info(String msg, MDC... mdcs) {
- if (mdcs == null || mdcs.length == 0) {
+ if (isNullOrEmpty(mdcs)) {
slf4jLogger.info(msg);
} else if (slf4jLogger.isInfoEnabled()) {
withLogContext(msg, mdcs, null, mt -> slf4jLogger.info(mt.message));
@@ -160,7 +160,7 @@ public class SparkLogger {
}
public void info(String msg, Throwable throwable, MDC... mdcs) {
- if (mdcs == null || mdcs.length == 0) {
+ if (isNullOrEmpty(mdcs)) {
slf4jLogger.info(msg, throwable);
} else if (slf4jLogger.isInfoEnabled()) {
withLogContext(msg, mdcs, throwable, mt -> slf4jLogger.info(mt.message, mt.throwable));
@@ -215,6 +215,10 @@ public class SparkLogger {
slf4jLogger.trace(msg, throwable);
}
+ private boolean isNullOrEmpty(MDC[] mdcs) {
+ return mdcs == null || mdcs.length == 0;
+ }
+
private void withLogContext(
String pattern,
MDC[] mdcs,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org