# HG changeset patch # User Elliott Baron # Date 1361987598 18000 # Node ID cf03638b6e7365dfa5909371ec44a918b1e458a8 # Parent 53ce942c35c1c58bc1c865063f7512d668413c62 Fix Swing Exceptions on connection failure I recently noticed that when starting the GUI without the agent running, sporadic exceptions would occur in Swing code. This seems to be caused by interleaving of two threads calling ConnectionHandler.changed. When DbService.connect fails to connect it throws a ConnectionException which was caught by Main.connect. In this catch clause, we are calling ConnectionHandler.changed, but at the same time the ConnectionListener fires. This causes the handler to be called twice from different threads. With this code removed, the sporadic exceptions no longer seem to occur. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005901.html diff -r 53ce942c35c1 -r cf03638b6e73 client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java --- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java Tue Feb 26 15:31:32 2013 -0500 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java Wed Feb 27 12:53:18 2013 -0500 @@ -235,9 +235,9 @@ try { dbService.connect(); } catch (Throwable t) { + // Note: DbService fires a ConnectionListener event when it + // fails to connect. No need to notify our handler manually. logger.log(Level.WARNING, "connection attempt failed: ", t); - // is this ever possible? - reconnectionHandler.changed(ConnectionStatus.FAILED_TO_CONNECT); } } });