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

Is the documentation for Concurrent::Map#put_if_absent inverted? #798

Closed
nerdrew opened this issue Feb 8, 2019 · 4 comments
Closed

Is the documentation for Concurrent::Map#put_if_absent inverted? #798

nerdrew opened this issue Feb 8, 2019 · 4 comments
Assignees
Labels
bug A bug in the library or documentation.

Comments

@nerdrew
Copy link

nerdrew commented Feb 8, 2019

The documentation looks like it says that it will return the new value if the key was not present and return nil if the new value was not inserted because the key was present.

It looks like the implementation is the opposite.

% pry -rconcurrent
[1] pry(main)> m = Concurrent::Map.new
=> #<Concurrent::Map:0x007f80e98124c0 entries=0 default_proc=nil>
[2] pry(main)> m.put_if_absent("a", 1)
=> nil
[3] pry(main)> m.put_if_absent("a", 2)
=> 1
[4] pry(main)> 
@nerdrew
Copy link
Author

nerdrew commented Feb 8, 2019

@pitr-ch
Copy link
Member

pitr-ch commented Mar 6, 2019

Thanks @nerdrew! You are right. Could you contribute a fix please?

@pitr-ch pitr-ch added bug A bug in the library or documentation. looking-for-contributor We are looking for a contributor to help with this issue. labels Mar 6, 2019
@edzhelyov
Copy link
Contributor

Hey, is this still open? I can take a stab at fixing it. The code needs to change in accordance with the documentation, right?

@pitr-ch pitr-ch removed the looking-for-contributor We are looking for a contributor to help with this issue. label Nov 17, 2019
@pitr-ch
Copy link
Member

pitr-ch commented Nov 17, 2019

@edzhelyov thank you! Please do. The behaviour is correct, it has to match https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html#putIfAbsent-K-V- so the documentation needs a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in the library or documentation.
Projects
None yet
Development

No branches or pull requests

3 participants