Skip to content

Double subscription check fails for ProxySubscriber with ReferenceStrength.STRONG #1

Description

@void256

I'm subscribing two different org.bushe.swing.event.ProxySubscriber instances using ReferenceStrength.STRONG that proxy to the same object. However, the double subscription check in ThreadSafeEventService does not detect the duplicate subscriber.

I think the reason for this is, that the resolving of the real object is done for the new object being subscribed only for ReferenceStrength.WEAK proxies and the check for duplicates in the existing subscribers resolves the proxied object regardless of the ReferenceStrength.

  1. Resolve of the new object being checked looks like so https://github.com/michaelbushe/EventBus/blob/master/src/org/bushe/swing/event/ThreadSafeEventService.java#L632
         isWeakProxySubscriber = proxySubscriber.getReferenceStrength() == ReferenceStrength.WEAK;
         if (isWeakProxySubscriber) {
            realSubscriber = ((ProxySubscriber) subscriber).getProxiedSubscriber();
         }
  1. Resolving of the existing subscribers looks like so https://github.com/michaelbushe/EventBus/blob/master/src/org/bushe/swing/event/ThreadSafeEventService.java#L2056
      if (existingSubscriber instanceof ProxySubscriber) {
         existingProxySubscriber = (ProxySubscriber) existingSubscriber;
         existingSubscriber = existingProxySubscriber.getProxiedSubscriber();
         if (existingProxySubscriber == null) {
            removeProxySubscriber(existingProxySubscriber, iterator);
         }
      }

So in case of a ReferenceStrength.STRONG ProxySubscriber we end up comparing the ProxySubscriber (new subscriber) with the proxied object (existing subscriber) which will not match and the duplicate entry is not being detected properly.

I think we should treat both ways of resolving the object in the same way!?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions