title: Java 8 Stream - NullPointerException when working with Custom Collector
body: <p>I have implemented a custom collector by implementing the Collector interface and overridding its methods. The Collector implementation is as follows:</p>
  
  <pre><code>class MyCustomCollector implements Collector&lt;Person, StringJoiner, String&gt;{
  
      @Override
      public Supplier&lt;StringJoiner&gt; supplier() {
          // TODO Auto-generated method stub
          return () -&gt; new StringJoiner("|");
      }
  
      @Override
      public BiConsumer&lt;StringJoiner, Person&gt; accumulator() {
          // TODO Auto-generated method stub
          return (joiner,person) -&gt; joiner.add(person.name.toUpperCase());
      }
  
      @Override
      public BinaryOperator&lt;StringJoiner&gt; combiner() {
          // TODO Auto-generated method stub
          return (joiner1, joiner2) -&gt; joiner1.merge(joiner2);
      }
  
      @Override
      public Function&lt;StringJoiner, String&gt; finisher() {
          // TODO Auto-generated method stub
          return StringJoiner::toString;
      }
  
      @Override
      public Set&lt;java.util.stream.Collector.Characteristics&gt; characteristics() {
          // TODO Auto-generated method stub
          return null;
      }
  }
  </code></pre>
  
  <p>Here is my Person class:</p>
  
  <pre><code>class Person implements Comparable&lt;Object&gt;{
      String name;
      int age;
  
      Person(String name, int age) {
          this.name = name;
          this.age = age;
      }
  
      @Override
      public String toString() {
          return name;
      }
  
      public int compareTo(Object obj){
          int returnValue;
          if(age ==((Person) obj).age)
              returnValue=0;
          else
              if(age &gt;((Person) obj).age)
                  returnValue = 1;
              else
                  returnValue =-1;
  
          return returnValue;
      }
  
      public boolean equals(Object obj)
      {
          if(!(obj instanceof Person))
              return false;
  
          return (age == ((Person) obj).age); 
      }
  
      public int hashCode()
      {  
          return name.hashCode();  
      } 
  
  }
  </code></pre>
  
  <p>And Here is my calling statements...</p>
  
  <pre><code>List&lt;Person&gt; persons =
          Arrays.asList(
              new Person("Max", 18),
              new Person("Peter", 23),
              new Person("Pamela", 23),
              new Person("David", 12),
              new Person("Pam", 23));
  String names2 = persons.stream()
              .collect(new MyCustomCollector());
  </code></pre>
  
  <p>When the above statement gets executed, i got a NullPointerException as follows:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NullPointerException
        at java.util.stream.ReduceOps$3.getOpFlags(ReduceOps.java:185)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
        at com.my.j8.TestStreams.main(TestStreams.java:231)</p>
  </blockquote>
  
  <p>Can anybody tell where i am making the mistake?</p>