Handle spurious wakeups correctly.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 13 Sep 2012 12:02:06 +0000 (14:02 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 13 Sep 2012 12:02:06 +0000 (14:02 +0200)
src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java

index 531275d..53a45b1 100644 (file)
@@ -399,14 +399,19 @@ public class WebOfTrustConnector {
                };
                pluginConnector.addConnectorListener(WOT_PLUGIN_NAME, identifier, connectorListener);
                synchronized (reply) {
-                       pluginConnector.sendRequest(WOT_PLUGIN_NAME, identifier, fields, data);
                        try {
-                               reply.wait();
-                       } catch (InterruptedException ie1) {
-                               logger.log(Level.WARNING, String.format("Got interrupted while waiting for reply on %s.", fields.get("Message")), ie1);
+                               pluginConnector.sendRequest(WOT_PLUGIN_NAME, identifier, fields, data);
+                               while (reply.getFields() == null) {
+                                       try {
+                                               reply.wait();
+                                       } catch (InterruptedException ie1) {
+                                               logger.log(Level.WARNING, String.format("Got interrupted while waiting for reply on %s.", fields.get("Message")), ie1);
+                                       }
+                               }
+                       } finally {
+                               pluginConnector.removeConnectorListener(WOT_PLUGIN_NAME, identifier, connectorListener);
                        }
                }
-               pluginConnector.removeConnectorListener(WOT_PLUGIN_NAME, identifier, connectorListener);
                logger.log(Level.FINEST, String.format("Received FCP Response for %s: %s", fields.get("Message"), (reply.getFields() != null) ? reply.getFields().get("Message") : null));
                if ((reply.getFields() == null) || "Error".equals(reply.getFields().get("Message"))) {
                        throw new PluginException("Could not perform request for " + fields.get("Message"));