title: Why list.contains(null) throwing null pointer exception?
body: <p>I have <code>List&lt;Long&gt; countriesList</code> which contains <code>Long</code> values which are country ids.</p>
  <p>Now I am iterating over some <code>List&lt;UserRequests&gt;</code> list by using <code>streams</code>.</p>
  <pre><code>userRequests.stream().
      forEach(userRequest-&gt;
      {
          UserData=userRepository.findById(userRequest.getId()); //fine
          if (CollectionUtils.isNotEmpty(countriesList) &amp;&amp; countriesList.contains(userRequest.getCountryId()))//getting NPE here
          {
              //do some operation
          }
      });
  </code></pre>
  <p>I tried to debug by evaluating individual statements.
  I have made sure <code>countriesList</code> have some data
  First part <code>CollectionUtils.isNotEmpty(countriesList)</code> is returning <code>true</code>.
  <code>userRequest</code> is also not null but <code>userRequest.getCountryId()</code> is null.
  And when I evaluated <code>countriesList.contains(userRequest.getCountryId())</code>, I am getting <code>Null pointer exception</code> here. why not <code>false</code> ?
  I am confused what wrong am I doing.
  Is default <code>list.contains(null)</code> behaviour is like that only or is it because I am calling it within <code>stream()</code>?</p>
  <p>Just for simplification I have created simple list and compared with <code>null</code>.</p>
  <pre><code>class Test {
      public static void main(String[] args) {
          List&lt;Long&gt; longList = List.of(1L, 2L, 3L);
          System.out.println(&quot;Comparing long list with null::&quot; + longList.contains(null));
      }
  }
  </code></pre>
  <p>This is the exception I am getting:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.NullPointerException
      at java.base/java.util.Objects.requireNonNull(Objects.java:222)
      at java.base/java.util.ImmutableCollections$AbstractImmutableList.indexOf(ImmutableCollections.java:166)
      at java.base/java.util.ImmutableCollections$AbstractImmutableList.contains(ImmutableCollections.java:197)
      at com.test.Test.main(Test.java:26)
  </code></pre>
  <p>But If I do:</p>
  <pre><code>    List&lt;Long&gt; longList = new ArrayList&lt;&gt;();
      longList.add(1L);
      System.out.println(&quot;Comparing long list with null::&quot; + longList.contains(null));
  </code></pre>
  <p>Why it is printing <code>false</code>? Why no <code>NullPointerException</code> here?</p>