Skip to content

Commit 5a8e470

Browse files
committed
DefaultSubscriptionRegistry's removeSubscriptionInternal defensively handles non-existing destinations
Issue: SPR-11832
1 parent 2cf88ac commit 5a8e470

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry {
4848
/** The maximum number of entries in the cache */
4949
private volatile int cacheLimit = DEFAULT_CACHE_LIMIT;
5050

51+
private PathMatcher pathMatcher = new AntPathMatcher();
52+
5153
private final DestinationCache destinationCache = new DestinationCache();
5254

5355
private final SessionSubscriptionRegistry subscriptionRegistry = new SessionSubscriptionRegistry();
5456

55-
private PathMatcher pathMatcher = new AntPathMatcher();
56-
5757

5858
/**
5959
* Specify the maximum number of entries for the resolved destination cache.
@@ -71,19 +71,20 @@ public int getCacheLimit() {
7171
}
7272

7373
/**
74-
* The PathMatcher to use.
74+
* Specify the {@link PathMatcher} to use.
7575
*/
7676
public void setPathMatcher(PathMatcher pathMatcher) {
7777
this.pathMatcher = pathMatcher;
7878
}
7979

8080
/**
81-
* The configured PathMatcher.
81+
* Return the configured {@link PathMatcher}.
8282
*/
8383
public PathMatcher getPathMatcher() {
8484
return this.pathMatcher;
8585
}
8686

87+
8788
@Override
8889
protected void addSubscriptionInternal(String sessionId, String subsId, String destination, Message<?> message) {
8990
this.subscriptionRegistry.addSubscription(sessionId, subsId, destination);
@@ -95,7 +96,7 @@ protected void removeSubscriptionInternal(String sessionId, String subsId, Messa
9596
SessionSubscriptionInfo info = this.subscriptionRegistry.getSubscriptions(sessionId);
9697
if (info != null) {
9798
String destination = info.removeSubscription(subsId);
98-
if (info.getSubscriptions(destination) == null) {
99+
if (destination != null && info.getSubscriptions(destination) == null) {
99100
this.destinationCache.updateAfterRemovedSubscription(destination, sessionId, subsId);
100101
}
101102
}
@@ -206,9 +207,9 @@ public void updateAfterRemovedSubscription(String destination, String sessionId,
206207
}
207208
}
208209
}
209-
for (String d : destinationsToRemove) {
210-
this.updateCache.remove(d);
211-
this.accessCache.remove(d);
210+
for (String destinationToRemove : destinationsToRemove) {
211+
this.updateCache.remove(destinationToRemove);
212+
this.accessCache.remove(destinationToRemove);
212213
}
213214
}
214215
}

0 commit comments

Comments
 (0)