hg: lambda/lambda/jdk: Implement groupBy for both ordered and unordered sources

Paul Sandoz paul.sandoz at oracle.com
Wed Oct 24 01:14:10 PDT 2012


On Oct 23, 2012, at 10:54 PM, Brian Goetz <brian.goetz at Oracle.COM> wrote:

> Good catch.  The null check here is cheap but the formatting is not, and 
> given that this is on a hot code path, probably should be adjusted to 
> use a static error message or inline the requireNonNull logic.
> 

Ouch, my bad, nice catch.

The simplest fix is just to remove the null check and defer to the check in CHM. Patch attached.

Paul.

diff -r 93ea6cccef22 src/share/classes/java/util/streams/ops/GroupByOp.java
--- a/src/share/classes/java/util/streams/ops/GroupByOp.java	Tue Oct 23 14:06:54 2012 -0700
+++ b/src/share/classes/java/util/streams/ops/GroupByOp.java	Wed Oct 24 10:13:18 2012 +0200
@@ -77,8 +77,7 @@
             Sink<S> sinkChain = helper.wrapSink(new Sink.OfValue<T>() {
                 @Override
                 public void accept(T t) {
-                    K key = Objects.requireNonNull(mapper.map(t), String.format("The element %s cannot be mapped to a null key", t));
-                    final Collection<T> sb = map.computeIfAbsent(key, (k) -> valueFactory.make());
+                    final Collection<T> sb = map.computeIfAbsent(mapper.map(t), (k) -> valueFactory.make());
                     synchronized (sb) {
                         sb.add(t);
                     }


More information about the lambda-dev mailing list