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

Int2IntHashMap methods don't work when using map via interface #98

Closed
vladimir-lifar opened this issue May 11, 2017 · 3 comments
Closed

Comments

@vladimir-lifar
Copy link

vladimir-lifar commented May 11, 2017

Some methods of Int2IntHashMap don't actually override corresponding methods of java.util.Map. Due to this fact we can't expose Int2IntHashMap as a Map<Integer, Integer> to external code.

computeIfAbsentUsingImplementation() works well, but computeIfAbsentUsingInterface() fails, because it uses java.util.Map.computeIfAbsent(...) which is not overridden.

@Test
public void computeIfAbsentUsingImplementation() {
    Int2IntHashMap int2IntHashMap = new Int2IntHashMap(-1);
    int key = 0;
    int result = int2IntHashMap.computeIfAbsent(key, k -> k);
    Assert.assertEquals(key, result);
}

@Test
public void computeIfAbsentUsingInterface() {
    Map<Integer, Integer> map = new Int2IntHashMap(-1);
    int key = 0;
    int result = map.computeIfAbsent(key, k -> k);
    Assert.assertEquals(key, result);
}

Agrona 0.9.3, JDK 8

@RichardWarburton
Copy link
Contributor

You shouldn't need to override computeIfAbsent, should be fine to inherit the default if you implement the Map interface properly. Looks like we're not dealing with nulls properly on get() or put(). I'll take a look.

@RichardWarburton
Copy link
Contributor

Thanks for the bug report.

@vladimir-lifar
Copy link
Author

vladimir-lifar commented May 11, 2017

@RichardWarburton, @mjpt777 many thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants