@@ -129,7 +129,9 @@ public Message start() throws IOException {
129129
130130 /* Start an asynchronous resolution */
131131 public void startAsync (ResolverListener listener ) {
132- this .listener = listener ;
132+ synchronized (this ) {
133+ this .listener = listener ;
134+ }
133135 send (0 );
134136 }
135137
@@ -140,6 +142,7 @@ public void startAsync(ResolverListener listener) {
140142 @ Override
141143 public void receiveMessage (Object id , Message m ) {
142144 log .debug ("received message" );
145+ ResolverListener listenerCopy ;
143146 synchronized (this ) {
144147 if (done ) {
145148 return ;
@@ -149,9 +152,11 @@ public void receiveMessage(Object id, Message m) {
149152 if (listener == null ) {
150153 notifyAll ();
151154 return ;
155+ } else {
156+ listenerCopy = listener ;
152157 }
153158 }
154- listener .receiveMessage (this , response );
159+ listenerCopy .receiveMessage (this , response );
155160 }
156161
157162 /*
@@ -161,6 +166,7 @@ public void receiveMessage(Object id, Message m) {
161166 @ Override
162167 public void handleException (Object id , Exception e ) {
163168 log .debug ("resolving failed" , e );
169+ ResolverListener listenerCopy = null ;
164170 synchronized (this ) {
165171 outstanding --;
166172 if (done ) {
@@ -225,6 +231,8 @@ public void handleException(Object id, Exception e) {
225231 if (listener == null ) {
226232 notifyAll ();
227233 return ;
234+ } else {
235+ listenerCopy = listener ;
228236 }
229237 }
230238 if (!done ) {
@@ -233,9 +241,9 @@ public void handleException(Object id, Exception e) {
233241 }
234242 /* If we're done and this is asynchronous, call the callback. */
235243 if (!(thrown instanceof Exception )) {
236- thrown = new RuntimeException (thrown . getMessage () );
244+ thrown = new RuntimeException (thrown );
237245 }
238- listener .handleException (this , (Exception ) thrown );
246+ listenerCopy .handleException (this , (Exception ) thrown );
239247 }
240248 }
241249
0 commit comments