title: Comparison method violates its general contract on generic comparator
body: <p>I have this generic method to sort a Map by value:</p>
  
  <pre><code>public static &lt;K, V extends Comparable&lt;? super V&gt;&gt; Map&lt;K, V&gt;
          sortByValue(Map&lt;K, V&gt; map) {
      Map&lt;K, V&gt; result = new LinkedHashMap&lt;&gt;();
      Stream&lt;Map.Entry&lt;K, V&gt;&gt; st = map.entrySet().stream();
  
      st.sorted(Map.Entry.comparingByValue())
              .forEachOrdered(e -&gt; result.put(e.getKey(), e.getValue()));
  
      return result;
  }
  </code></pre>
  
  <p>And sometimes I'm getting <code>java.lang.IllegalArgumentException: Comparison method violates its general contract!</code>. Is there any particular reason this code might behave like this?</p>
  
  <p>I am aware of the <a href="https://stackoverflow.com/questions/8327514/comparison-method-violates-its-general-contract">duplicate question</a>, but this example involves generics, lambdas and built-in methods, which makes it more complex and I would appreciate some explanation.</p>