title: Trying to Sort in Java 8 with Nulls in the Data
body: <p>I am trying to sort a list that I get by the comparator given. I am passing the comparator through the NullsLast method to get a Null-Friendly version of my comparator like the JavaDoc states. However, when I run the code I am still getting a Null Pointer Exception when I pass a String comparator to the method. </p>
  
  <pre><code>private &lt;T&gt; void sortWithDirection(List&lt;T&gt; details, boolean isAscending, Comparator&lt;T&gt; comparator){
  
      if(isAscending){
          details.sort(Comparator.nullsLast(comparator));
      } else {
          details.sort(Comparator.nullsLast(comparator.reversed()));
      }
  }
  
  List&lt;UserDTO&gt; users = new ArrayList&lt;&gt;();
  sortWithDirection(users, false, Comparator.comparing(UserDTO::getName));
  </code></pre>
  
  <p>Am I using this method wrong? Is there a different way that I can prevent NPEs without removing them from the result set?</p>