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

davidarthur pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 75a84116b38 MINOR: Use more appropriate exception when validate 
builder parameters (#21369)
75a84116b38 is described below

commit 75a84116b384705cef036dfa95781d85fcda5b24
Author: Maros Orsak <[email protected]>
AuthorDate: Wed Feb 18 15:51:00 2026 +0100

    MINOR: Use more appropriate exception when validate builder parameters 
(#21369)
    
    This PR changes exception types to be more concrete when handling the
    parameters of the builder. `IllegalStateException` is more semantically
    appropriate here as it indicates the builder is in an invalid state,
    i.e., missing pararmeter)
    
    Reviewers: Matthias J. Sax <[email protected]>, David Arthur
     <[email protected]>
    
    Signed-off-by: see-quick <[email protected]>
---
 .../main/java/kafka/server/builders/LogManagerBuilder.java | 14 +++++++-------
 .../java/kafka/server/builders/ReplicaManagerBuilder.java  |  8 ++++----
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/kafka/server/builders/LogManagerBuilder.java 
b/core/src/main/java/kafka/server/builders/LogManagerBuilder.java
index 6de61915e8e..7cc427c9ae9 100644
--- a/core/src/main/java/kafka/server/builders/LogManagerBuilder.java
+++ b/core/src/main/java/kafka/server/builders/LogManagerBuilder.java
@@ -148,13 +148,13 @@ public class LogManagerBuilder {
     }
 
     public LogManager build() {
-        if (logDirs == null) throw new RuntimeException("you must set 
logDirs");
-        if (configRepository == null) throw new RuntimeException("you must set 
configRepository");
-        if (initialDefaultConfig == null) throw new RuntimeException("you must 
set initialDefaultConfig");
-        if (cleanerConfig == null) throw new RuntimeException("you must set 
cleanerConfig");
-        if (scheduler == null) throw new RuntimeException("you must set 
scheduler");
-        if (brokerTopicStats == null) throw new RuntimeException("you must set 
brokerTopicStats");
-        if (logDirFailureChannel == null) throw new RuntimeException("you must 
set logDirFailureChannel");
+        if (logDirs == null) throw new IllegalStateException("you must set 
logDirs");
+        if (configRepository == null) throw new IllegalStateException("you 
must set configRepository");
+        if (initialDefaultConfig == null) throw new IllegalStateException("you 
must set initialDefaultConfig");
+        if (cleanerConfig == null) throw new IllegalStateException("you must 
set cleanerConfig");
+        if (scheduler == null) throw new IllegalStateException("you must set 
scheduler");
+        if (brokerTopicStats == null) throw new IllegalStateException("you 
must set brokerTopicStats");
+        if (logDirFailureChannel == null) throw new IllegalStateException("you 
must set logDirFailureChannel");
         return new LogManager(CollectionConverters.asScala(logDirs).toSeq(),
                               
CollectionConverters.asScala(initialOfflineDirs).toSeq(),
                               configRepository,
diff --git 
a/core/src/main/java/kafka/server/builders/ReplicaManagerBuilder.java 
b/core/src/main/java/kafka/server/builders/ReplicaManagerBuilder.java
index 5426d55a64d..d79894bf5ce 100644
--- a/core/src/main/java/kafka/server/builders/ReplicaManagerBuilder.java
+++ b/core/src/main/java/kafka/server/builders/ReplicaManagerBuilder.java
@@ -100,10 +100,10 @@ public class ReplicaManagerBuilder {
 
     public ReplicaManager build() {
         if (config == null) config = new KafkaConfig(Map.of());
-        if (logManager == null) throw new RuntimeException("You must set 
logManager");
-        if (metadataCache == null) throw new RuntimeException("You must set 
metadataCache");
-        if (logDirFailureChannel == null) throw new RuntimeException("You must 
set logDirFailureChannel");
-        if (alterPartitionManager == null) throw new RuntimeException("You 
must set alterIsrManager");
+        if (logManager == null) throw new IllegalStateException("You must set 
logManager");
+        if (metadataCache == null) throw new IllegalStateException("You must 
set metadataCache");
+        if (logDirFailureChannel == null) throw new IllegalStateException("You 
must set logDirFailureChannel");
+        if (alterPartitionManager == null) throw new 
IllegalStateException("You must set alterIsrManager");
         if (brokerTopicStats == null) brokerTopicStats = new 
BrokerTopicStats(config.remoteLogManagerConfig().isRemoteStorageSystemEnabled());
         // Initialize metrics in the end just before passing it to 
ReplicaManager to ensure ReplicaManager closes the
         // metrics correctly. There might be a resource leak if it is 
initialized and an exception occurs between

Reply via email to