Skip to content

Commit 8a79ea2

Browse files
authored
KAFKA-19676 EpochState should override close to avoid throwing IOException (apache#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]>
1 parent 865beb6 commit 8a79ea2

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

raft/src/main/java/org/apache/kafka/raft/EpochState.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ default Optional<LogOffsetMetadata> highWatermark() {
5959
* User-friendly description of the state
6060
*/
6161
String name();
62+
63+
/**
64+
* Since all subclasses implement the Closeable interface while none throw any IOException,
65+
* this implementation is provided to eliminate the need for exception handling in the close operation.
66+
*/
67+
@Override
68+
void close();
6269
}

raft/src/main/java/org/apache/kafka/raft/QuorumState.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import org.slf4j.Logger;
2929

30-
import java.io.IOException;
31-
import java.io.UncheckedIOException;
3230
import java.util.List;
3331
import java.util.Optional;
3432
import java.util.OptionalInt;
@@ -736,12 +734,7 @@ private void durableTransitionTo(EpochState newState) {
736734

737735
private void memoryTransitionTo(EpochState newState) {
738736
if (state != null) {
739-
try {
740-
state.close();
741-
} catch (IOException e) {
742-
throw new UncheckedIOException(
743-
"Failed to transition from " + state.name() + " to " + newState.name(), e);
744-
}
737+
state.close();
745738
}
746739

747740
EpochState from = state;

0 commit comments

Comments
 (0)