From 6ac84f9a529c47e2dd9546f898c75adc611f4fdd Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Wed, 4 Oct 2017 23:05:14 -0500 Subject: [PATCH] Decreasing count when removing subscription listener --- .../graphenej/models/SubscriptionResponse.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java b/graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java index 2b2f6d0..8edbfcd 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/models/SubscriptionResponse.java @@ -111,13 +111,15 @@ public class SubscriptionResponse { * to be removed from the list. */ public void removeSubscriptionListener(SubscriptionListener subscriptionListener){ - int currentCount = listenerTypeCount.get(subscriptionListener.getInterestObjectType()); - if(currentCount != 0){ - this.listenerTypeCount.put(subscriptionListener.getInterestObjectType(), currentCount); - }else{ - System.out.println("Trying to remove subscription listener, but none is registered!"); + if(listenerTypeCount.containsKey(subscriptionListener.getInterestObjectType())){ + int currentCount = listenerTypeCount.get(subscriptionListener.getInterestObjectType()); + if(currentCount > 0){ + this.listenerTypeCount.put(subscriptionListener.getInterestObjectType(), currentCount - 1); + this.mListeners.remove(subscriptionListener); + }else{ + System.out.println("Trying to remove subscription listener, but none is registered!"); + } } - this.mListeners.remove(subscriptionListener); } /**