From 961a839ac33e995e8c73350ca33f93da1271eb7f Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Tue, 2 May 2023 23:44:04 +0200 Subject: [PATCH] Fix crash when onNetworkChanged was called before link was initialized This race condition could happen on slow devices --- .../kdeconnect/Backends/LanBackend/LanLinkProvider.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java index 937db24a..9dcb4bc4 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -369,7 +369,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis NetworkPacket identity = NetworkPacket.createIdentityPacket(context); if (tcpServer == null || !tcpServer.isBound()) { - throw new RuntimeException("Wont't broadcast UDP packet if TCP socket is not ready"); + throw new IllegalStateException("Wont't broadcast UDP packet if TCP socket is not ready"); } int port = tcpServer.getLocalPort(); identity.set("tcpPort", port); @@ -420,7 +420,11 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis @Override public void onNetworkChange() { - broadcastUdpPacket(); + try { + broadcastUdpPacket(); + } catch (IllegalStateException e) { + e.printStackTrace(); + } } @Override