title: NullPointerException when binding ConfigurationProperties (Spring Boot)
body: <p>I am struggling with some code and I don't have a clue why...
  Here is my code:</p>
  
  <pre><code>@SpringBootApplication
  @EnableConfigurationProperties(WorkflowRootProperties.class)
  @ComponentScan
  @ActiveProfiles("test")
  public class TestApplication {
      public static void main(String[] args) {    
          SpringApplication.run(TestApplication.class, args);
      }
  }
  </code></pre>
  
  <p>And my properties bean</p>
  
  <pre><code>@ConfigurationProperties("workflow")
  public class WorkflowRootProperties {
      private List&lt;Datacenter&gt; datacenter = new ArrayList&lt;&gt;();
  
      public List&lt;Datacenter&gt; getDatacenter() {
          return datacenter;
      }
  
      public void setDatacenter(List&lt;Datacenter&gt; datacenter) {
          this.datacenter = datacenter;
      }
  }
  </code></pre>
  
  <p>Which references another bean</p>
  
  <pre><code>public class EnvProperties {
      public static class Datacenter {
          private List&lt;Env&gt; env = new ArrayList&lt;&gt;();
  
          public List&lt;Env&gt; getEnv() {
              return env;
          }
  
          public void setEnv(List&lt;Env&gt; env) {
              this.env = env;
          }
      }
  
      public static class Env {
          private List&lt;Instance&gt; instance = new ArrayList&lt;&gt;();
  
          public List&lt;Instance&gt; getInstance() {
              return instance;
          }
  
          public void setInstance(List&lt;Instance&gt; instance) {
              this.instance = instance;
          }
      }
  
      public static class Instance {
          private String port;
  
          public String getPort() {
              return port;
          }
  
          public void setPort(String port) {
              this.port= port;
          }
      }
  }
  </code></pre>
  
  <p>Finally, my properties are</p>
  
  <pre><code>workflow.datacenter[1].env[1].instance[1].port=8080
  workflow.datacenter[2].env[1].instance[1].port=8082
  workflow.datacenter[1].env[1].instance[2].port=8080
  </code></pre>
  
  <p>My Error is at init, I get a NPE which I cannot understand.</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Failed to load ApplicationContext...</p>
    
    <p>Caused by:
    org.springframework.boot.context.properties.bind.BindException: Failed
    to bind properties under 'workflow.datacenter' to
    java.util.List     at
    org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:250)
      at
    org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:226)
      at
    org.springframework.boot.context.properties.bind.Binder.lambda$bindBean$4(Binder.java:331)
      at
    org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:72)
      at
    org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:61)
      at
    org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:53)...</p>
    
    <p>Caused by: java.lang.NullPointerException: null     at
    java.util.TreeMap.compare(TreeMap.java:1294)  at
    java.util.TreeMap.put(TreeMap.java:538)   at
    java.util.TreeSet.add(TreeSet.java:255)   at
    java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
      at
    java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1235)
      at
    java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
      at
    java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:270)
      at java.util.Iterator.forEachRemaining(Iterator.java:116)   at
    java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
      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
    org.springframework.boot.context.properties.bind.IndexedElementsBinder.assertNoUnboundChildren(IndexedElementsBinder.java:137)...</p>
  </blockquote>
  
  <p>Could you please help me?</p>