RFR: 8247402: Documentation for Map::compute contains confusing implementation requirements
Pavel Rappo
prappo at openjdk.java.net
Wed Nov 25 16:41:57 UTC 2020
On Sat, 21 Nov 2020 09:21:06 GMT, John Lin <github.com+1290376+johnlinp at openjdk.org> wrote:
>> @johnlinp, you cannot create a CSR by yourself at the moment. Someone else will have to do that for you. Might as well be me. So here's my proposal: come up with the meat, then I'll help you with the paperwork.
>>
>> For starters, have a look at existing CSRs (you don't need a JBS account for that). For example, https://bugs.openjdk.java.net/issues/?jql=issuetype%3DCSR%20and%20Subcomponent%3Djava.util%3Acollections%20
>>
>> Fill in an informal CSR template inline in this thread, and we'll proceed from that point. Is that okay?
>
> @pavelrappo Please see my proposed CSR below. Thank you.
>
> # Map::compute should have a clearer implementation requirement.
>
> ## Summary
>
> java.util.Map::compute should have a clearer implementation requirement in its documentation.
>
> ## Problem
>
> The documentation of the implementation requirements for Map::compute has the following problems:
> 1. It lacks of return statements for most of the if-else cases.
> 1. The indents are 3 spaces, while the convention is 4 spaces.
> 1. The if-else is overly complicated and can be simplified.
>
> ## Solution
>
> Rewrite the documentation of Map::compute to match its default implementation.
>
> ## Specification
>
> diff --git a/src/java.base/share/classes/java/util/Map.java b/src/java.base/share/classes/java/util/Map.java
> index b1de34b42a5..c3118a90581 100644
> --- a/src/java.base/share/classes/java/util/Map.java
> +++ b/src/java.base/share/classes/java/util/Map.java
> @@ -1113,17 +1113,12 @@ public interface Map<K, V> {
> * <pre> {@code
> * V oldValue = map.get(key);
> * V newValue = remappingFunction.apply(key, oldValue);
> - * if (oldValue != null) {
> - * if (newValue != null)
> - * map.put(key, newValue);
> - * else
> - * map.remove(key);
> - * } else {
> - * if (newValue != null)
> - * map.put(key, newValue);
> - * else
> - * return null;
> + * if (newValue != null) {
> + * map.put(key, newValue);
> + * } else if (oldValue != null) {
> + * map.remove(key);
> * }
> + * return newValue;
> * }</pre>
> *
> * <p>The default implementation makes no guarantees about detecting if the
@johnlinp In any case, you'd also need to update the surrounding prose; we need to remove this:
returning the current value or {@code null} if absent:```
-------------
PR: https://git.openjdk.java.net/jdk/pull/714
More information about the core-libs-dev
mailing list