Skip to content

Should org.apache.dubbo.registry.support.AbstractRegistry#getRegistered returns unmodifiable sets? #3106

Closed
@kezhenxu94

Description

@kezhenxu94

I notice that the method org.apache.dubbo.registry.support.AbstractRegistry#getRegistered just returns the internal reference of registered, and everyone can modify this Set outside the Registry, is this a good practice?

An example is that in org.apache.dubbo.registry.support.AbstractRegistryTest#testRegister, there is something like:

//test multiple urls
abstractRegistry.getRegistered().clear();

we clear the registered urls outside the Registry, maybe it's not a big deal because we just do some logs and remove the url in unregister method:

    @Override
    public void unregister(URL url) {
        if (url == null) {
            throw new IllegalArgumentException("unregister url == null");
        }
        if (logger.isInfoEnabled()) {
            logger.info("Unregister: " + url);
        }
        registered.remove(url);
    }

but still, it'll lose some logs and if we add more logics in the unregister method in the future, it could be dangerous.

I suggest returning a unmodifiable set in the getRegistered method and unregister all urls one by one or providing a method such as unregisterAll.

There is the same problem with method getSubscribed, getNotified, etc.

What do you think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions