Collectors.toMap IllegalStateException: Duplicate key when no duplication is possible
<p>I keep hitting this error and I'm not able to make sense of it, because it complains about a value that is <strong>present exactly once</strong>.</p>

<pre><code>Exception in thread "main" java.lang.IllegalStateException: Duplicate key wp-admin/admin-ajax.php#13236
at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133)
at java.util.HashMap.merge(HashMap.java:1245)
at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320)
at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at &lt;my code&gt;
</code></pre>

<p>This is the original code:</p>

<pre><code>reader.lines().filter(line -&gt; line.startsWith(TAG_MAPPED_NODE)).map(line -&gt; {
    final String[] splitted = line.split(" ");
    if (splitted.length != 3)
        throw new IllegalStateException("Unexpected line: " + line);
    return splitted;(splitted[1],splitted[2]);
}).collect(Collectors.toMap(t -&gt; t[1], t -&gt; t[2]));
</code></pre>

<p>However, the value it complains about exists exactly once. Validation code:</p>

<pre><code>List&lt;String&gt; usefulLines =
    reader.lines().filter(line -&gt; line.startsWith(TAG_MAPPED_NODE)).collect(Collectors.toList());
List&lt;String&gt; trouble =
    usefulLines.stream().filter(line -&gt; line.contains("wp-admin/admin-ajax.php#13236")).collect(Collectors.toList());
System.out.println("Trouble size: " + trouble.size());
return usefulLines.stream().map(line -&gt; {
    final String[] splitted = line.split(" ");
    if (splitted.length != 3)
        throw new IllegalStateException("Unexpected line: " + line);
    return splitted;
}).collect(Collectors.toMap(t -&gt; t[1], t -&gt; t[2]));
</code></pre>

<p>And the output is: <code>Trouble size: 1</code></p>

<p>So, there is only one entry that has this value (and, I must add, I'm storing it in the Value side of the Map, <em>not</em> the Key)</p>

<p>System configuration:</p>

<ul>
<li>Java version: openjdk version "1.8.0_72"</li>
<li>IDE: IntelliJ IDEA 2016.1</li>
<li>OS: Fedora 22 64 bit</li>
</ul>

<p>So how in the world am I getting that exception? This looks like a JDK bug to me - anybody seeing something I did wrong?</p>