Fixing potential concurrent modification exception
This commit is contained in:
Christopher L. Shannon (cshannon) 2016-11-01 10:25:01 -04:00
parent a8a650cbee
commit 5c80eda321
1 changed files with 13 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@ -174,15 +175,22 @@ public class AMQ6477Test {
@SuppressWarnings("unchecked")
protected List<MessageReference> getSubscriptionMessages(Subscription sub) throws Exception {
Field f = null;
Field dispatchedField = null;
Field dispatchLockField = null;
if (sub instanceof TopicSubscription) {
f = TopicSubscription.class.getDeclaredField("dispatched");
dispatchedField = TopicSubscription.class.getDeclaredField("dispatched");
dispatchLockField = TopicSubscription.class.getDeclaredField("dispatchLock");
} else {
f = PrefetchSubscription.class.getDeclaredField("dispatched");
dispatchedField = PrefetchSubscription.class.getDeclaredField("dispatched");
dispatchLockField = PrefetchSubscription.class.getDeclaredField("dispatchLock");
}
dispatchedField.setAccessible(true);
dispatchLockField.setAccessible(true);
synchronized (dispatchLockField.get(sub)) {
return new ArrayList<MessageReference>((List<MessageReference>)dispatchedField.get(sub));
}
f.setAccessible(true);
return (List<MessageReference>) f.get(sub);
}
}