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

DoubleArrayTrie里的LongestSearcher的next方法,当传入的treemap的value为null时,会引发bug #1673

Closed
1 task done
tiandiweizun opened this issue Aug 24, 2021 · 1 comment
Assignees
Labels

Comments

@tiandiweizun
Copy link

tiandiweizun commented Aug 24, 2021

Describe the bug

DoubleArrayTrie里的LongestSearcher的next方法,当传入的treemap的value为null时,会引发bug
image

Code to reproduce the issue

 public void testLongestSearcherWithNullValue() {
        TreeMap<String, String> buildFrom = new TreeMap<String, String>();
        TreeMap<String, String> buildFromValueNull = new TreeMap<String, String>();
        String[] keys = new String[]{"he", "her", "his"};
        for (String key : keys) {
            buildFrom.put(key, key);
            buildFromValueNull.put(key, null);
        }
        DoubleArrayTrie<String> trie = new DoubleArrayTrie<String>(buildFrom);
        DoubleArrayTrie<String> trieValueNull = new DoubleArrayTrie<String>(buildFromValueNull);

        String text = "her3he6his-hers! ";

        DoubleArrayTrie<String>.LongestSearcher searcher = trie.getLongestSearcher(text.toCharArray(), 0);
        DoubleArrayTrie<String>.LongestSearcher searcherValueNull = trieValueNull.getLongestSearcher(text.toCharArray(), 0);

        while (true) {
            boolean next = searcher.next();
            boolean nextValueNull = searcherValueNull.next();

            if (next && nextValueNull) {
                assertTrue(searcher.begin == searcherValueNull.begin && searcher.length == searcherValueNull.length);
            } else if (next || nextValueNull) {
                assert false;
                break;
            } else {
                break;
            }
        }
    }

Describe the current behavior
由于map传入的value为null,即使存在,也查不到

Expected behavior
A clear and concise description of what you expected to happen.
根据length或者index进行判断
修复参见pull request (#1674)

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): win10
  • Python version: xxx
  • HanLP version: 1.8.2

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

  • I've completed this form and searched the web for solutions.
@hankcs
Copy link
Owner

hankcs commented Aug 24, 2021

感谢反馈,已经合并

@hankcs hankcs closed this as completed Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants