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

chia7712 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 8a79ea2e5bd KAFKA-19676 EpochState should override close to avoid 
throwing IOException (#20508)
8a79ea2e5bd is described below

commit 8a79ea2e5bde348e4ab3e45c28a7b2661fc6bfef
Author: jimmy <[email protected]>
AuthorDate: Thu Sep 11 18:21:35 2025 +0800

    KAFKA-19676 EpochState should override close to avoid throwing IOException 
(#20508)
    
    Jira: [KAFKA-19676](https://issues.apache.org/jira/browse/KAFKA-19676)
    All subclasses of EpochState do not throw an IOException when closing,
    so catching it is unnecessary. We could override close to remove the
    IOException declaration.
    
    Reviewers: Jhen-Yung Hsu <[email protected]>, TaiJuWu
     <[email protected]>, Chia-Ping Tsai <[email protected]>
---
 raft/src/main/java/org/apache/kafka/raft/EpochState.java  | 7 +++++++
 raft/src/main/java/org/apache/kafka/raft/QuorumState.java | 9 +--------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/raft/src/main/java/org/apache/kafka/raft/EpochState.java 
b/raft/src/main/java/org/apache/kafka/raft/EpochState.java
index 338f6603181..e4afba6893a 100644
--- a/raft/src/main/java/org/apache/kafka/raft/EpochState.java
+++ b/raft/src/main/java/org/apache/kafka/raft/EpochState.java
@@ -59,4 +59,11 @@ public interface EpochState extends Closeable {
      * User-friendly description of the state
      */
     String name();
+
+    /**
+     * Since all subclasses implement the Closeable interface while none throw 
any IOException,
+     * this implementation is provided to eliminate the need for exception 
handling in the close operation.
+     */
+    @Override
+    void close();
 }
diff --git a/raft/src/main/java/org/apache/kafka/raft/QuorumState.java 
b/raft/src/main/java/org/apache/kafka/raft/QuorumState.java
index 1462b824fab..4ae24c84eaf 100644
--- a/raft/src/main/java/org/apache/kafka/raft/QuorumState.java
+++ b/raft/src/main/java/org/apache/kafka/raft/QuorumState.java
@@ -27,8 +27,6 @@ import org.apache.kafka.server.common.OffsetAndEpoch;
 
 import org.slf4j.Logger;
 
-import java.io.IOException;
-import java.io.UncheckedIOException;
 import java.util.List;
 import java.util.Optional;
 import java.util.OptionalInt;
@@ -736,12 +734,7 @@ public class QuorumState {
 
     private void memoryTransitionTo(EpochState newState) {
         if (state != null) {
-            try {
-                state.close();
-            } catch (IOException e) {
-                throw new UncheckedIOException(
-                    "Failed to transition from " + state.name() + " to " + 
newState.name(), e);
-            }
+            state.close();
         }
 
         EpochState from = state;

Reply via email to