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 <jhenyunghsu@gmail.com>, TaiJuWu
 <tjwu1217@gmail.com>, Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
jimmy 2025-09-11 18:21:35 +08:00 committed by GitHub
parent 865beb6ede
commit 8a79ea2e5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View File

@ -59,4 +59,11 @@ public interface EpochState extends Closeable {
* User-friendly description of the state * User-friendly description of the state
*/ */
String name(); 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();
} }

View File

@ -27,8 +27,6 @@ import org.apache.kafka.server.common.OffsetAndEpoch;
import org.slf4j.Logger; import org.slf4j.Logger;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
@ -736,12 +734,7 @@ public class QuorumState {
private void memoryTransitionTo(EpochState newState) { private void memoryTransitionTo(EpochState newState) {
if (state != null) { if (state != null) {
try { state.close();
state.close();
} catch (IOException e) {
throw new UncheckedIOException(
"Failed to transition from " + state.name() + " to " + newState.name(), e);
}
} }
EpochState from = state; EpochState from = state;