From 38165f9ef743f7c8df7a036349850f31fd89bc32 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 11 Apr 2023 19:15:54 +0200 Subject: [PATCH] Use instanceof patterns in BGPPeer Reduce the risk of mismatched casts by using an explicit pattern. Change-Id: I238585f6dc29456dc56853a511533cbbd8b8816e Signed-off-by: Robert Varga --- .../protocol/bgp/rib/impl/BGPPeer.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java index 6a84134ea3..6a0996bd7e 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPPeer.java @@ -258,10 +258,10 @@ public class BGPPeer extends AbstractPeer implements BGPSessionListener { @Override public void onMessage(final BGPSession session, final Notification msg) throws BGPDocumentedException { - if (msg instanceof Update) { - onUpdateMessage((Update) msg); - } else if (msg instanceof RouteRefresh) { - onRouteRefreshMessage((RouteRefresh) msg); + if (msg instanceof Update update) { + onUpdateMessage(update); + } else if (msg instanceof RouteRefresh routeRefresh) { + onRouteRefreshMessage(routeRefresh); } else { LOG.info("Ignoring unhandled message class {}", msg.getClass()); } @@ -377,8 +377,8 @@ public class BGPPeer extends AbstractPeer implements BGPSessionListener { } }); - if (currentSession instanceof BGPSessionStateProvider) { - ((BGPSessionStateProvider) currentSession).registerMessagesCounter(this); + if (currentSession instanceof BGPSessionStateProvider stateProvider) { + stateProvider.registerMessagesCounter(this); } final GracefulRestartCapability advertisedGracefulRestartCapability = session.getAdvertisedGracefulRestartCapability(); @@ -512,8 +512,8 @@ public class BGPPeer extends AbstractPeer implements BGPSessionListener { final RIBSupport ribSupport = rib.getRibSupportContext().getRIBSupport(key); // not particularly nice - if (ribSupport != null && currentSession instanceof BGPSessionImpl) { - final ChannelOutputLimiter limiter = ((BGPSessionImpl) currentSession).getLimiter(); + if (ribSupport != null && currentSession instanceof BGPSessionImpl bgpSession) { + final ChannelOutputLimiter limiter = bgpSession.getLimiter(); final AdjRibOutListener adjRibOut = AdjRibOutListener.create(peerId, key, rib.getYangRibId(), rib.getCodecsRegistry(), ribSupport, rib.getService(), limiter, mpSupport); @@ -702,24 +702,24 @@ public class BGPPeer extends AbstractPeer implements BGPSessionListener { @Override public synchronized BGPSessionState getBGPSessionState() { - if (currentSession instanceof BGPSessionStateProvider) { - return ((BGPSessionStateProvider) currentSession).getBGPSessionState(); + if (currentSession instanceof BGPSessionStateProvider stateProvider) { + return stateProvider.getBGPSessionState(); } return null; } @Override public synchronized BGPTimersState getBGPTimersState() { - if (currentSession instanceof BGPSessionStateProvider) { - return ((BGPSessionStateProvider) currentSession).getBGPTimersState(); + if (currentSession instanceof BGPSessionStateProvider stateProvider) { + return stateProvider.getBGPTimersState(); } return null; } @Override public synchronized BGPTransportState getBGPTransportState() { - if (currentSession instanceof BGPSessionStateProvider) { - return ((BGPSessionStateProvider) currentSession).getBGPTransportState(); + if (currentSession instanceof BGPSessionStateProvider stateProvider) { + return stateProvider.getBGPTransportState(); } return null; } -- 2.36.6