From c17310c88e67d9cb0d0ca19b75b9adc886b99373 Mon Sep 17 00:00:00 2001 From: see-quick Date: Thu, 29 Jan 2026 14:28:27 +0100 Subject: [PATCH] [MINOR] Use more appropriate exception when validate builder parameters Signed-off-by: see-quick --- .../kafka/server/builders/LogManagerBuilder.java | 14 +++++++------- .../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 6de61915e8efc..7cc427c9ae941 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 LogManagerBuilder setInitialTaskDelayMs(long initialTaskDelayMs) { } 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 5426d55a64da3..d79894bf5ce2d 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 ReplicaManagerBuilder setBrokerTopicStats(BrokerTopicStats brokerTopicSta 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