Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GroupKey in nacos-client config have some bug #5018

Closed
shalk opened this issue Mar 5, 2021 · 4 comments · Fixed by #5100
Closed

GroupKey in nacos-client config have some bug #5018

shalk opened this issue Mar 5, 2021 · 4 comments · Fixed by #5100
Assignees
Labels
area/Client Related to Nacos Client SDK kind/bug Category issues or prs related to bug.
Milestone

Comments

@shalk
Copy link
Contributor

shalk commented Mar 5, 2021

Describe the bug
1. GroupKey.getKey will not check dataId or groupId is blank
2. GroupKey.parseKey("f++bar") get wrong result [f, bar, null]

Expected behavior

  1. GroupKey.getKey should throw RunTimeException, if dataId or groupId is blank
  2. GroupKey.parseKey("f++bar") should throw IllegalArgumentException

Acutally behavior
A clear and concise description of what you actually to happen.

How to Reproduce

these unit tests will fail.

public class GroupKeyTest {
   @Rule
    public final ExpectedException thrown = ExpectedException.none();
    
    @Test
    public void testParseKeyIllegalArgumentException4() {
        thrown.expect(IllegalArgumentException.class);
        GroupKey.parseKey("f++bar");
    }
    
    @Test
    public void testGetKeyDatIdParam() {
        thrown.expect(IllegalArgumentException.class);
        GroupKey.getKey("", "a");
    }
    
    @Test
    public void testGetKeyGroupParam() {
        thrown.expect(IllegalArgumentException.class);
        GroupKey.getKey("a", "");
    }
}

Desktop (please complete the following information):

  • OS: [Ubuntu]
  • Version nacos-client develop branch
  • Module [client/config]

Additional context
Add any other context about the problem here.

@shiyiyue1102
Copy link
Collaborator

dataId or groupId is blank should not be allowed, "DEFAULT_GROUP" will be set outside if groupId is empty

@shalk
Copy link
Contributor Author

shalk commented Mar 5, 2021

dataId or groupId is blank should not be allowed, "DEFAULT_GROUP" will be set outside if groupId is empty

@shiyiyue1102 this code will not throw exception,

   String dataId = "";
        String group = "";
        configService.addListener(dataId, group, new Listener() {
            @Override
            public void receiveConfigInfo(String configInfo) {
                System.out.println("receive:" + configInfo);
            }
            
            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        System.out.println("group = " + group);

null2defaultGroup will check group is null, not empty

    public void addTenantListeners(String dataId, String group, List<? extends Listener> listeners)
            throws NacosException {
        group = null2defaultGroup(group);

@KomachiSion KomachiSion added the kind/discussion Category issues related to discussion label Mar 8, 2021
@shiyiyue1102
Copy link
Collaborator

dataId or groupId is blank should not be allowed, "DEFAULT_GROUP" will be set outside if groupId is empty

@shiyiyue1102 this code will not throw exception,

   String dataId = "";
        String group = "";
        configService.addListener(dataId, group, new Listener() {
            @Override
            public void receiveConfigInfo(String configInfo) {
                System.out.println("receive:" + configInfo);
            }
            
            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        System.out.println("group = " + group);

null2defaultGroup will check group is null, not empty

    public void addTenantListeners(String dataId, String group, List<? extends Listener> listeners)
            throws NacosException {
        group = null2defaultGroup(group);

Yes,because 'DEFAULT_GROUP' will be set if group is blank, if we focus on the method GroupKey.getKey ,blank group is not valid and should throw exception.

@shalk
Copy link
Contributor Author

shalk commented Mar 9, 2021

dataId or groupId is blank should not be allowed, "DEFAULT_GROUP" will be set outside if groupId is empty

@shiyiyue1102 this code will not throw exception,

   String dataId = "";
        String group = "";
        configService.addListener(dataId, group, new Listener() {
            @Override
            public void receiveConfigInfo(String configInfo) {
                System.out.println("receive:" + configInfo);
            }
            
            @Override
            public Executor getExecutor() {
                return null;
            }
        });
        System.out.println("group = " + group);

null2defaultGroup will check group is null, not empty

    public void addTenantListeners(String dataId, String group, List<? extends Listener> listeners)
            throws NacosException {
        group = null2defaultGroup(group);

Yes,because 'DEFAULT_GROUP' will be set if group is blank, if we focus on the method GroupKey.getKey ,blank group is not valid and should throw exception.

so we could change null2defaultGroup to blank2defaultGroup, and add param check in GroupKey.

@KomachiSion KomachiSion added area/Config area/Client Related to Nacos Client SDK labels Mar 12, 2021
@KomachiSion KomachiSion added kind/bug Category issues or prs related to bug. and removed area/Config kind/discussion Category issues related to discussion labels Mar 29, 2021
@KomachiSion KomachiSion added this to the 1.4.2 milestone Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Client Related to Nacos Client SDK kind/bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants