powertools-lambda-java
powertools-lambda-java copied to clipboard
Some code suggestion from CodeGuru
-
The code is using ConcurrentHashMap, but the usage of containsKey() and get() may not be thread-safe. In between the check and the get() another thread can remove the key and the get() will return null. Fix: Consider calling get(), checking instead of your current check if the returned object is null, and then using that object only, without calling get() again.
-
This code uses '%s' to format int: 'size' expression. Use %d, not %s, for integers. This ensures locale-sensitive formatting.
-
Replacing put() with putIfAbsent() to help prevent accidental overwriting. putIfAbsent() puts the value only if the ConcurrentHashMap does not contain the key and therefore avoids overwriting the value written there by the other thread's putIfAbsent().
Hi @XinyuLiu5566 Thanks for opening the PR. There seems to be some failing tests. Can you please look into it ?
Thanks @jeromevdl for merging #984. Could you please close this PR, as it contains the same changes and my PR was created just to fix some issues with this one.
Fixed with #984