Affects: Spring Boot Version - 2.2.2.RELEASE


I have the following application.properties file:

metric.prefix=dev
metric.kafka.report_period_ms=60000
metric.kafka.clusters.0.groupstopics.0.group_id=test1
metric.kafka.clusters.0.groupstopics.0.topics=test_topic1,test_topic2
metric.kafka.clusters.0.groupstopics.1.group_id=test2
metric.kafka.clusters.0.groupstopics.1.topics=test_topic3,test_topic4
metric.kafka.clusters.0.groupstopics.2.group_id=test3
metric.kafka.clusters.0.groupstopics.2.topics=test_topic5,test_topic6

In this case I have properly configured ConfigurationProperties, something like this:

{
  "prefix":"dev",
  "cluster":[
    {
      "groupstopics": [
        {
          "group_id": "test1",
          "topics": "test_topic1,test_topic2"
        },
        {
          "group_id": "test2",
          "topics": "test_topic3,test_topic4"
        },
        {
          "group_id": "test3",
          "topics": "test_topic5,test_topic6"
        }
      ]
    }
  ]
}

If I skip, for example, metric.kafka.clusters.0.groupstopics.1 completely, my properties file looks like this:

metric.prefix=dev
metric.kafka.report_period_ms=60000
metric.kafka.clusters.0.groupstopics.0.group_id=test1
metric.kafka.clusters.0.groupstopics.0.topics=test_topic1,test_topic2
metric.kafka.clusters.0.groupstopics.2.group_id=test3
metric.kafka.clusters.0.groupstopics.2.topics=test_topic5,test_topic6

It's also properly mapped, I have the following ConfigurationProperties:

{
  "prefix":"dev",
  "cluster":[
    {
      "groupstopics": [
        {
          "group_id": "test1",
          "topics": "test_topic1,test_topic2"
        },
        {
          "group_id": "test3",
          "topics": "test_topic5,test_topic6"
        }
      ]
    }
  ]
}

However, if I skip the first element of metric.kafka.clusters.0.groupstopics, my properties file looks like this:

metric.prefix=dev
metric.kafka.report_period_ms=60000
metric.kafka.clusters.0.groupstopics.1.group_id=test2
metric.kafka.clusters.0.groupstopics.1.topics=test_topic3,test_topic4
metric.kafka.clusters.0.groupstopics.2.group_id=test3
metric.kafka.clusters.0.groupstopics.2.topics=test_topic5,test_topic6

In this case, I have wrongly mapped ConfigurationProperties, groupstopics is set as null:

{
  "prefix":"dev",
  "cluster":[
    {
      "groupstopics": null
    }
  ]
}

Is it expected behaviour? Can it be fixed? Thanks!

Comment From: wilkinsona

Thanks for the report. Spring Boot 2.2 is no longer supported. 2.3 has also reached the end of its OSS support period. Can you please verify that you problem still occurs with Spring Boot 2.4.x or 2.5.x?

Comment From: AntonZakharankou

Thank you for your reply. I verified Spring Boot 2.4.10 and 2.5.4, the problem occurs for both versions.

Comment From: philwebb

I've tried to replicate the issue in ArrayBinderTests but I didn't have much luck. @AntonZakharankou can you share a sample project that replicates the issue?

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: AntonZakharankou

@philwebb below you can find the repo that contains a sample project that replicates the issue. https://github.com/AntonZakharankou/issue-27784 In order to replicate the issue you can comment/remove the value of myprop.array.0

Comment From: philwebb

Looking at the same I think this is expected behavior. Items in the list need to run sequentially starting from [0]. You can't skip indexes. I think we could do with improving the documentation for this.

I'm still a little confused as to why in your initial report the following binds two entries:

metric.prefix=dev
metric.kafka.report_period_ms=60000
metric.kafka.clusters.0.groupstopics.0.group_id=test1
metric.kafka.clusters.0.groupstopics.0.topics=test_topic1,test_topic2
metric.kafka.clusters.0.groupstopics.2.group_id=test3
metric.kafka.clusters.0.groupstopics.2.topics=test_topic5,test_topic6

I would have expected groupstopics to contain only element 0. If you have a sample that replicates that one then please share it.

If you really want to be able to skip items, perhaps binding to a Map<Integer, Value> would be better. That should allow you to skip elements.

Comment From: AntonZakharankou

@philwebb thank you for your response. Unfortunately, I'm not able to reproduce the case that you are asking about. Probably I used different version of Spring Boot.